[Twisted-Python] Small practice application
Hi everyone, I've decided to write a Tic-Tac-Toe gameserver and client(no biggie, just for getting used to twisted as I'm pretty new to it). The gameserver facilitates the connection between two clients and maintains the game state. I'm having trouble deciding how to create factories and protocols for the server. What I am expecting is a toss to decide who plays first followed by a move from client in a sequential manner. The client sends messages of the format "MOV 2 3" to specify co-ordinates on the board, when prompted by a "MAKE MOVE" from the server. So the server should alternate between connections, read and send data. How do I accomplish something such as this? Thanks, zm
Hi everyone,
I've decided to write a Tic-Tac-Toe gameserver and client(no biggie, just for getting used to twisted as I'm pretty new to it). The gameserver facilitates the connection between two clients and maintains the game state.
I'm having trouble deciding how to create factories and protocols for the server.
I have made little progress in this regard, please view it here. http://paste.pocoo.org/show/269325/ I intend to read lines from clients based on the value of ServerFactory.player in the following manner. - In the lineReceived() method. I check the value of self.factory.player. If the current instance is the (self.factory.player)th element of self.factory.connections. If yes, read the input, parse and make changes to the table. This is the basic idea for reading data and detecting which client it came from. However, I am confused on how to write data over to a particular player(0 or 1). Is there any way I could choose to write to a particular object? zm
What I am expecting is a toss to decide who plays first followed by a move from client in a sequential manner. The client sends messages of the format "MOV 2 3" to specify co-ordinates on the board, when prompted by a "MAKE MOVE" from the server.
So the server should alternate between connections, read and send data. How do I accomplish something such as this?
Thanks, zm
On Sep 30, 2010, at 1:51 AM, Zubin Mithra wrote:
However, I am confused on how to write data over to a particular player(0 or 1). Is there any way I could choose to write to a particular object?
Sure, make self.factory.connections into a dictionary which maps player names to connection objects, instead of a simple list. Or simply do: for connection in self.factory.connections: if connection.username == 'desired-username': connection.doSomething() This isn't really a twisted question, it's a basic Python question :).
participants (2)
-
Glyph Lefkowitz
-
Zubin Mithra