[Twisted-Python] Clean pb solution for two-way object sync?

Glyph glyph at twistedmatrix.com
Thu Sep 26 19:52:04 MDT 2013


On Sep 25, 2013, at 11:05 PM, Daniel Sank <sank.daniel at gmail.com> wrote:

> This isn't THAT bad. The client's requestMove is thin and unecessary (I put it there for illustration). Still I need to have two separate classes with corresponding methods to handle moving the piece.

That's OK.  Don't try to reduce your number of classes just for the sake of having fewer classes.  Each class should have a clearly defined responsibility.  In this case, your responsibilities correspond directly to the things that have to happen on the server (validating the move) and the things that have to happen on the client (updating the graphical representation to correspond to the new game state).  Having more, smaller classes means that it's easier for you to understand each class on its own, and programming is nothing if not the act of promoting local understanding :).

If anything, you should have an additional class to separate out your remote_* responders and the actual internal state.

> This seems like the kind of thing I could twisted.pb to solve more cleanly if I only would look in the right place.


I don't know if this is going to directly address any of your concerns, but have you considered using twisted.spread.flavors.Cacheable?  That will atomically combine the propagation of initial state with the provision of the back-propagation channel for updates to that state.  It's designed for exactly what you're doing, maintaining parallel simulated states on client and server.

Does that help at all?

-glyph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20130926/5452ebb0/attachment.html>


More information about the Twisted-Python mailing list