I am making a simple multiplayer economic game in pygame. It consists of turns of a certain length, at the end of which, data is sent to the central server. A few quick calculations are done on the data and the results are sent back to the players. My question is how I should implement the network support. I was looking at Twisted and at Pyro and any suggestions or advice would be appreciated.
Asked
Active
Viewed 3,793 times
3 Answers
1
I've nothing against Twisted and PyRo, but the sort of simple messages you're going to be sending don't require anything like that and might be overcomplicated by using some sort of framework. Pickling an object and sending it over a socket is actually a very easy operation and well worth trying, even if you do eventually go with a more heavyweight framework. Don't fear the network!

Kylotan
- 18,290
- 7
- 46
- 74
-
1Using pickle for network protocols is an *extremely bad* idea. Here are two recent examples of this: http://plone.org/products/plone/security/advisories/cve-2007-5741 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-0668 – Jean-Paul Calderone Aug 20 '09 at 21:14
-
Yes, that's a very valid point regarding pickle. I stand by my assertion that performing a trivial serialisation and handling the networking yourself is a good idea though. Does Python offer no standard capability for pure serialisation of data without potential side-effects? – Kylotan Aug 21 '09 at 11:05
-
@Kylotan: Just use twisted and you're done. What's really "overcomplicated" is to try to rewrite what twisted does by hand. Twisted is a complicated, well written and tested piece of code, trying to replicate it yourself almost cetainly means that you'll end up with a half-working, half-baked poor-quality code. Dealing with network is much more than opening a raw low-level socket and naively pushing data. Don't fear the framework!! – nosklo Sep 26 '09 at 22:53
-
I can't say I agree, sorry! Twisted is a convoluted piece of software with a rather idiosyncratic set of terminology and its own set of significant problems (eg. http://twistedmatrix.com/trac/ticket/3901). I prefer Python overall, but I would still prefer to write my own networking layer in C than to use Twisted. Networking is really not as complicated as people fear it is. – Kylotan Sep 27 '09 at 00:03
-
What's up with that ticket link? What does a multi-process work queue (which exists, but is not distributed as part of the Twisted project) have to do with the point you're making? – Jean-Paul Calderone Feb 29 '12 at 13:33
-
I couldn't say; I posted it 2.5 years ago and the issue description isn't very clear (nor can I see if it's changed). – Kylotan Feb 29 '12 at 14:31
-
@Kylotan: If you want a serialization method different to pickle, you could try json. Batteries included. – Speckinius Flecksis Apr 24 '12 at 19:36
-
@SpeckiniusFlecksis: Python's json library (at least Python 2's) is not capable of serialising a Python object directly - for that you need to either write custom encoders/decoders or use something like the jsonpickle library. But I personally don't have need for this functionality. – Kylotan Apr 24 '12 at 19:47
1
There are a number of plug-and-play libraries tailored specifically to work nicely with PyGame on the pygame.org website.
These include PodSixNet, PygLibs.net, and my own Mastermind (which is, at the risk of self-aggrandizement, lightweight, easy to use, and comes with a simple tutorial).

geometrian
- 14,775
- 10
- 56
- 132