[Twisted-Python] the right twisted base classes for my project
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? (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?) tia for any replies, stephen.
On Dec 18, 2016, at 5:05 PM, elguavas <elguavas@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.ht... <https://twistedmatrix.com/documents/16.6.0/api/twisted.test.proto_helpers.ht...> - 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
On 19/12/16 12:31, Glyph Lefkowitz wrote:
On Dec 18, 2016, at 5:05 PM, elguavas <elguavas@gmail.com [...] 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.
ok, really the important part of what i now see was quite a long winded ramble ;) was this:
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.
so calls in both directions and the server being able to identify deal with _specific_ clients or a _specific subset_ of clients all clients. this last parts are what seemed to fit with pb and avatar on my reading. i'm not looking for any implementation details at this point, just wanting to make sure i got off on the right foot using twisted, since it has so many parts...
The thing that you want to look at to make testing easy [...] eye on for that.)
cool, thanks.
(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 :).
ok, nice to know. i'm also hoping the twisted pb stuff will accomplish some of the lifting for me, ie that i won't have to go quite so low level... i guess i'll see on that when i start to suck it. ;)
-glyph
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (2)
-
elguavas
-
Glyph Lefkowitz