Reputation: 405
I plan to make a Python game server but I can't see how to set it up.
The problem I have is that I need the server to listen for connections (with socket.socket.accept()
?) but it hangs the code until a connection is made, which means the server can't do anything else while it is waiting.
Is multi-threading the solution to this?
The other question is whether each client should connect at the start of the game and stay connected for the duration, or if the connection should be made every second to send/receive data.
Upvotes: 0
Views: 2164
Reputation: 18794
Correct, socket.accept()
blocks by design. To handle connection in the background see SocketServer.ThreadingMixIn
for example.
http://docs.python.org/library/socketserver.html#asynchronous-mixins
Upvotes: 2