Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi-client server
#1
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()
Reply
#2
You should read this: http://pgbovine.net/python-async-io-walkthrough.htm
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
Is using raw sockets desired? Because this is exactly the sort of thing Twisted was made for.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Networking Issues - Python GUI client and server connection always freezes Veritas_Vos_Liberabit24 0 679 Mar-21-2023, 03:18 AM
Last Post: Veritas_Vos_Liberabit24
  creating python server and client in a pc kucingkembar 4 1,958 Nov-29-2021, 01:37 PM
Last Post: kucingkembar
  Real-Time output of server script on a client script. throwaway34 2 2,011 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  How to take the tar backup files form remote server to local server sivareddy 0 1,871 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  Python sockets : Client sending to the server nico31780 0 2,276 May-17-2020, 07:56 PM
Last Post: nico31780
  client-server pictures mcgrim 4 2,919 Oct-25-2019, 09:53 PM
Last Post: micseydel
  Client Server Game Pygame not responding Damien 2 3,101 Aug-04-2018, 06:19 PM
Last Post: micseydel
  ssh to multi server and keep seesion to working inspirer 0 2,276 May-17-2018, 09:33 AM
Last Post: inspirer
  Async server/client Bokka 2 3,843 May-29-2017, 03:09 PM
Last Post: Bokka
  How to use a UDP server and client to setup a chat abrew132 2 3,720 Mar-20-2017, 06:22 PM
Last Post: abrew132

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020