An echo protocol
Before we write our first client and server programs, we need to decide how they are going to interact with each other, that is we need to design a protocol for their communication.
Our echo server should listen until a client connects and sends a bytes string, then we want it to echo that string back to the client. We only need a few basic rules for doing this. These rules are as follows:
Communication will take place over TCP.
The client will initiate an echo session by creating a socket connection to the server.
The server will accept the connection and listen for the client to send a bytes string.
The client will send a bytes string to the server.
Once it sends the bytes string, the client will listen for a reply from the server
When it receives the bytes string from the client, the server will send the bytes string back to the client.
When the client has received the bytes string from the server, it will close its socket to end the session.
These steps are straightforward enough...