Python Forum
Multi-client server - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Multi-client server (/thread-3571.html)



Multi-client server - Saga - Jun-04-2017

I'm trying to change this code to be multi-user.. I read a little bit about using select function instead of using threads but I can't understand how to use it in my code.

Here's my code so far:

server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   server_sock.bind((SERVER_IP, SERVER_PORT))
   server_sock.listen(1)
   client_sock, client_address = server_sock.accept()
   client_sock.sendall("Welcome to the server!")
   answer = ""

   while (True):
       msg = client_sock.recv(1024)
       if (msg == "Hello"):
           answer = "Hello"
       elif (msg == "QUIT"):
           client_sock.sendall("Bye")
           break
       else:
           answer = "Error!"
       client_sock.sendall(answer)

   client_sock.close()
   server_sock.close()



RE: Multi-client server - DeaD_EyE - Jul-09-2017

You should read this: http://pgbovine.net/python-async-io-walkthrough.htm


RE: Multi-client server - nilamo - Jul-18-2017

Is using raw sockets desired? Because this is exactly the sort of thing Twisted was made for.