Running the Echo Server
00:00 Let’s now run our server and client and see them working. Remember, you have to start the server first. So in a terminal shell, you’d launch the server. You won’t see any output yet because the program is waiting to accept a connection.
00:16 You’ll need a different terminal shell on the same computer to run the client while the server still runs. When you launch that, the echoed message will be displayed right away.
00:28 But when you look back at the server’s console, you should see where it displayed the connection made to it. Let’s do that. I have two different terminal shells running in iTerm2. On the top one, I’ll launch the server.
00:51 Notice that the program is still running. I don’t have the system prompt. The socket has been created, and the server is listening for a connection to accept. Now go down to the bottom shell and launch the client.
01:12 That didn’t take long. You can see the output with the message echoed back from the server. And if you look at the top half of the screen, you’ll see that the terminal has displayed the connection information.
01:24
Notice the port number 53985 is the one established by the socket .accept()
function. Each time a client accesses the server, a different port will be used, so expect to see different numbers when you run the program.
01:42 In the next lesson, you’ll look at tools to help you diagnose when things might not quite be working right.
Become a Member to join the conversation.