Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to do client-server communication via sockets in Python
    primarykey
    data
    text
    <p>I have been banging my head against a socket issue for the last two weeks to no avail. I have a setup of 12 'client' machines and one server machine. The server is given a large task, splits it into 12 smaller tasks and then distributes them to the 12 clients. The clients churn away and once they finish their task, they are supposed to let the server know that they have finished via socket communication. For some reason, this has only been working spottily or not at all (both, the server and the clients, just sit in the while loop). </p> <p>Here is the code on the server:</p> <pre><code>socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) socket.bind(('localhost', RandomPort)) socket.listen(0) socket.settimeout(0.9) [Give all the clients their tasks, then do the following:] while 1: data = 'None' IP = [0,0] try: Client, IP = socket.accept() data = Client.recv(1024) if data == 'Done': Client.send('Thanks') for ClientIP in ClientIPList(): if ClientIP == IP[0] and data == 'Done': FinishedCount += 1 if FinishedCount == 12: break except: pass </code></pre> <p>Here is the code on all the clients: </p> <pre><code>[Receive task from server and execute. Once finished, do the following:] while 1: try: f = socket.socket(socket.AF_INET, socket.SOCK_STREAM) f.connect((IPofServer, RandomPort)) f.settimeout(0.5) f.send('Done') data = f.recv(1024) if data == 'Thanks': f.shutdown(socket.SHUT_RDWR) f.close() break except: f.close() time.sleep(2+random.random()*5) </code></pre> <p>I have used Wireshark and found that the packets are flying around. Yet, the "FinishedCount" never seems to increase... Is there anything glaringly wrong that I have missed in setting this up? This is my first exposure to sockets....</p> <p>Thank you all for your help in advance!</p> <p>EDIT: I've made the following changes to the code:</p> <p>On the server: socket.listen is now socket.listen(5)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload