Developing a network protocol with Python

Lawrence Oluyede raims at
Tue Dec 13 06:45:51 CET 2005

Il 2005-12-12, Laszlo Zsolt Nagy <gandalf at> ha scritto:
>   Hello,
> I would like to develop a new network protocol, where the server and the 
> clients are Python programs.

You should use Twisted for this:

Writing clients

Writing servers

> I think to be effective, I need to use TCP_NODELAY, and manually 
> buffered transfers.
> I would like to create a general messaging object that has methods like
> sendinteger
> recvinteger
> sendstring
> recvstring

You can inherit from twisted.internet.protocol.Protocol or one of its
subclasses, they handle buffering and all sort of these things for
you. Cannot have to reinvent the wheel.

> To be more secure, I think I can use this loads function to transfer 
> more elaborate python stuctures:
> def loads(s):
>     """Loads an object from a string.
>     @param s: The string to load the object from.
>     @return: The object loaded from the string. This function will not 
> unpickle globals and instances.
>     """
>     f = cStringIO.StringIO(s)
>     p = cPickle.Unpickler(f)
>     p.find_global = None
>     return p.load()

Using untrusted pickle loading is *NOT* more secure:

Lawrence -
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"

More information about the Python-list mailing list