Book Image

Learning Python Network Programming

By : Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington
Book Image

Learning Python Network Programming

By: Dr. M. O. Faruque Sarker, Samuel B Washington, Sam Washington

Overview of this book

Table of Contents (17 chapters)
Learning Python Network Programming
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Communication will take place over TCP.

  2. The client will initiate an echo session by creating a socket connection to the server.

  3. The server will accept the connection and listen for the client to send a bytes string.

  4. The client will send a bytes string to the server.

  5. Once it sends the bytes string, the client will listen for a reply from the server

  6. When it receives the bytes string from the client, the server will send the bytes string back to the client.

  7. 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...