Implementing a simple TCP client and TCP server
In this section, we are going to introduce concepts for creating an application oriented to passing messages between a client and server using the TCP protocol. The concept behind the development of this application is that the socket server is responsible for accepting client connections from a specific IP address and port.
Implementing a server and client with sockets
In Python, a socket can be created that acts as a client or server.
The idea behind developing this application is that a client may connect to a given host, port, and protocol by a socket. The socket server, on the other hand, is responsible for receiving client connections within a particular port and protocol:
- First, create a
socket
object for the server:server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- Once the
socket
object has been created, we need to establish on which port our server will listen using the...