I'm working on a game (Risk). I've already finished set-up, so a solution that doesn't require me to completely redesign networking would be preferable. The problem is I've gotten to main gameplay, and I need to allow messages from multiple users at the same time. The general idea is that when one player is taking their turn, another player can send a forfeit message, and still exit out of the game without crashing the whole server. Is there a way to do this, possibly using threading?
Asked
Active
Viewed 96 times
0
-
Server-client model: Any client that connects to the server is free to disconnect without affecting the others. Yes, that involves threading. Will also require server sockets. – Makoto Mar 10 '13 at 07:28
-
If you start doing threaded sockets I'd recommend you check out the [`SocketServer`](http://docs.python.org/2/library/socketserver.html) module. – Mar 10 '13 at 07:30
-
If you're using TCP there is no such thing as simultaneous messages over a socket. – user207421 Mar 10 '13 at 08:58
-
I've used Tornado for these kind of projects before. It's a async http server that can also handle websockets. You can even use SockJS as a compatibility layer for browsers that don't support websockets. – aychedee Mar 10 '13 at 11:40
1 Answers
1
There is no reason that your main thread should be blocked on one connection.
You need one listening thread, when a connection is made background threads handle communications to clients.
You do need to maintian a bullet proof state machine so that clients know the appropriate messages they can send at any given state, and the server needs to know which valid messages can be processed at any given state. Search stackoverflow, you'll find many examples, such as this: Sockets example

Community
- 1
- 1

Erez Robinson
- 794
- 4
- 9
-
Look here for more info specific to Python: http://docs.python.org/2/library/socketserver.html – Erez Robinson Mar 11 '13 at 08:24