How it works...

Clients and servers create their respective sockets, and the server listens to them on a port. The client makes a connection request to the server. It should be noted that we can have two different port numbers because one could only be dedicated to outgoing traffic, and the other could only be dedicated to entry. This depends on the host configuration.

Essentially, the client's local port does not necessarily coincide with the server's remote port. The server receives the request and, if accepted, a new connection is created. Now, the client and server communicate through a virtual channel, between the socket and the server, which is created specifically for the data flow of the data socket connection.

Consistent with what was mentioned in the first phase, the server creates the data socket because the first one is used exclusively for managing requests. Therefore, it is possible that there are many clients communicating with the server using the data socket created by the server for them. The TCP protocol is connection-oriented, which means that when there is no longer a need to communicate, the client communicates this to the server and the connection is closed.

To run the example, execute the server: 

C:>python server.py 

Then, execute the client (in a different Windows terminal):

C:>python client.py

The result on the client side should report the address (addr) and report port as connected:

Connected with[addr],[port]('192.168.178.11', 58753)

However, on the server side, the result should be as follows:

Time connection server:Sun Mar 31 20:59:38 2019
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset