Concurrent I/O
If you're adventurous, then you may have tried connecting to our server using more than one client at once. If you tried sending messages from both of them, then you'd have seen that it does not work as we might have hoped. If you haven't tried this, then give it a go.
A working echo session on the client should look like this:
Type message, enter to send. 'q' to quit hello world Sent message: hello world Received echo: hello world Closed connection to server
However, when trying to send a message by using a second connected client, we'll see something like this:
Type message, enter to send. 'q' to quit hello world Sent message: hello world
The client will hang when the message is sent, and it won't get an echo reply. You may also notice that if we send a message by using the first connected client, then the second client will get its response. So, what's going on here?
The problem is that the server can only listen for the messages from one client at a time. As soon as the...