Developing a network protocol with Python

Lawrence Oluyede raims at dot.com
Tue Dec 13 00:45:51 EST 2005


Il 2005-12-12, Laszlo Zsolt Nagy <gandalf at designaproduct.biz> 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
http://twistedmatrix.com/projects/core/documentation/howto/clients.html

Writing servers
http://twistedmatrix.com/projects/core/documentation/howto/servers.html


> 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:
http://www.python.org/doc/2.2.3/lib/pickle-sec.html
and
http://www.livejournal.com/users/jcalderone/15864.html


-- 
Lawrence - http://www.oluyede.org/blog
"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