Python network sockets programming tutorial

In this tutorial you will learn about in network programming. You will learn about the client-server model that is in use for the World Wide Web, E-mail and many other applications.

Client server (with email protocol)The client server model is a model where there are n clients and one server. The clients make data requests to a server. The server replies to those messages received. A client can be any device such as your computer or tablet. Servers are generally dedicated computers which are to be connected 24/7.

Limitations of the server code
The server code above can only interact with one client. If you try to connect with a second terminal it simply won’t reply to the new client. To let the server interact with multiple clients you need to use multi-threading. We rebuild the server script to accept multiple client connections:

Application protocol

So far we have simply sent messages back and forth. Every message can have a specific meaning in an application. This is known as the protocol. The meaning of these messages must be the same on both the sender and receiver side. The Transport Layer below makes sure that messages are received (TCP). The Internet Layer is the IPv4 protocol. All we have to define is the Application Layer.

Below we modified the server to accept simple commands (We use the non-threading server for simplicity). We changed the port to 64. Server code with a protocol:

4 thoughts on “Python network sockets programming tutorial”

Compared to the human communication: The web is a language on top of sockets, this computer language is called ‘http’. A network programming program can speak any language (‘http’,’email’,’ftp’,’irc’..). “Web programming : network” is as “English : sounds”