One solution might be to use an asynchronous library , which simplifies calls between the server and the client.
Here is an example that you could use (adapted from this site )
In deamon.py , a ChatServer object is ChatServer . Each time a connection is made, a ChatHandler object is inherited from asynchat.async_chat . This object collects data and fills it in self.buffer .
When calling a special line calls the terminator, the data must be completed and the found_terminator method is found_terminator . It is in this method that you write your own code.
In sender.py you create a ChatClient object inherited from asynchat.async_chat , establish a connection in the constructor, define a terminator (in case of a server response!), And call the push method to send data. You must add a terminator string to your data so that the server knows when it can stop reading data.
daemon.py:
import asynchat import asyncore import socket
sender.py:
import asynchat import asyncore import socket import threading
source share