0

I'm currently making a guessing game in Python and I'm trying to use select.select to allow multiple clients to connect to my server but I cannot wrap my head around how to use select.select. I've look all over the internet but all the tutorials I've come across are for chat servers which I can't seem to relate to.

I was just wondering how I'd let multiple clients connect to my server through select.select. And also how would I send/receive data to/from individual clients using select.select

user3665310
  • 1
  • 1
  • 2
  • There may be some clues here: http://stackoverflow.com/questions/12194701/asynchronous-sockets-with-select-python It's not clear exactly what you are stuck on. Can you be more specific? – doctorlove Dec 05 '15 at 12:24
  • This may be help (http://stackoverflow.com/questions/10605083/python-asyncore-keep-track-of-clients) – Amar Lakshya Pawar Dec 05 '15 at 12:31

1 Answers1

1

I've look all over the internet but all the tutorials I've come across are for chat servers which I can't seem to relate to.

There's no difference between a chat server and game server regarding the use of select.select.

I was just wondering how I'd let multiple clients connect to my server through select.select.

You'd pass the server socket (which you called listen on) in the rlist argument to select; if after return from select the server socket is in the first list (the objects that are ready for reading) of the returned triple of lists, you'd call accept on the server socket and thus get the new client socket, which you'd append to the rlist in subsequent select calls.

And also how would I send/receive data to/from individual clients using select.select

If after return from select a client socket is in the first list (the objects that are ready for reading) of the returned triple of lists, you'd receive data by calling recv on that client socket.
You don't need to use select for writing; you'd just send data by calling send.

See the question "Handle multiple requests with select" for an example server.

Armali
  • 18,255
  • 14
  • 57
  • 171