[Twisted-Python] the right twisted base classes for my project

Glyph Lefkowitz glyph at twistedmatrix.com
Sun Dec 18 18:31:59 MST 2016


> On Dec 18, 2016, at 5:05 PM, elguavas <elguavas at gmail.com> wrote:
> 
> hi all. i have a project with a networked aspect that i'm thinking of rewriting to use twisted. i'd like to ask for any input on the best twisted functions to base my rewrite on for my usage case, thanks.
> 
> the project is a fairly simple "games room" that lets a small number of users (from 2 up to a handful, lets say 12 max) join to play simple 2d board games against each other. there is also a general chat among current players function.
> 
> i originally wrote the networking code for this using python's stdlib asyncore and asynchat modules, implementing a basic rpc-like mechanism to allow clients and server to communicate via simple structured string "messages".
> 
> i have to say if it was a only bit of a nightmare to code, it was a _lot_ of a nightmare to test and debug... anyway, so i'm rewriting the networking code and looking at twisted and i'd like to make sure i start off using the right parts of twisted for the job right from the beginning.
> 
> the networking is based on having a server, that maintains central game state and coordinates it among the clients, and clients that connect to the sever to participate in games.
> 
> the clients need to be able to call functions on the server. the server needs to be able to return data to the clients and also to call functions back on specific clients, or subsets of clients, or all clients.
> 
> i've had a good look through the twisted docs and i'm thinking that perspective broker is what probably i need, likely along with its avatar functionality.
> 
> is this a sensible way to go or am i overlooking something obvious?

This is definitely sensible, but it's not really specific enough to nail down any longer answer.  The thing that you want to look at to make testing easy is https://twistedmatrix.com/documents/16.6.0/api/twisted.test.proto_helpers.html <https://twistedmatrix.com/documents/16.6.0/api/twisted.test.proto_helpers.html> - stuff in this module will help you hook up your tests to an in-memory network.  (We also have some internal test helpers which make this even easier, but which need a publicly-documented interface - https://twistedmatrix.com/trac/ticket/5167 <https://twistedmatrix.com/trac/ticket/5167> is a good ticket to keep an eye on for that.)

> (oh, and a last questionlet would be: if that would be the right parts of twisted to use, what would that buy me above the other possibility i'm considering, which is rewiriting using python's new asyncio stuff?)


Twisted's event loop is already compatible with asyncio, so whatever you write should basically be compatible with it.  I would not worry about that right now :).

-glyph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20161218/dd0d7695/attachment-0002.html>


More information about the Twisted-Python mailing list