Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Running the Multi-Connection Client and Server

00:00 In this lesson, you’ll see the multiconnection echo server and client working. Now that you’ve seen the code for the new echo client and server, you’re going to see them executing. You’ll need two separate terminal windows, one for the server and one for the client.

00:17 Remember, these programs now take the host and port values as command-line arguments. Recall this code in the server, checking that those values were there.

00:26 If they’re not provided, the program displays a short message on the proper way to start the program, and then exits. In addition to the host and port, the client wants to know how many connections you want to create. Let’s do this.

00:43 Again, you can see two different terminal windows on the screen. The top one will have the server, which is started this way.

00:52 Again, it’s going to use the loopback address and listen on port 65432. It displays a message that it’s listening, waiting to accept a connection. Now start the client,

01:11 telling the client to connect to the loopback host on Port 65432 and make three connections. The output happens rather quick.

01:25 Notice first, the client connects to the server three times, sends each pair of messages on each, and then prints them when echoed back. Because the selector is dealing with concurrent activities, it’s not guaranteed that these things will happen in the order you expected.

01:43 Notice that Message 1 from connection 2 was sent before Message 2 from connection 1, and if you ran this program again, you might see the output of activities in a different order.

01:59 Looking back at the server, you can see it received three connections, echoed back three pairs of messages, and then closed three connections. And again, because we’re dealing with concurrent events, there’s no guarantee the exact order that those events might happen.

02:15 The server just sees three separate connections. It doesn’t know what order the client created them.

02:25 Next, you’ll review what you’ve learned so far.

Become a Member to join the conversation.