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: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.
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.
Become a Member to join the conversation.