looking for UDP package, network programming guidance

Gerhard Häring gh at ghaering.de
Mon Jul 7 19:43:00 CEST 2003


Tom Plunket wrote:
> [...]
> Searching the web turned up Twisted, although it seems like it
> might be a bit bigger than I would have hoped (in terms of,
> "there's a huge package here to figure out"), but as far as I can
> tell it's the only UDP solution out there.  Is this the case? [...]

No, Python's standard library supports socket as well, and that's what 
Twisted builds upon :-)

Something like this should be a rough start for an UDP client (untested):

#v+
import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto('Bing!', ('192.168.0.1', 5555))
#v-

For an example UDP client and server this heartbeat recipe might be 
useful: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52302

> [...] Finally, I'm also somewhat of a babe in the woods with network
> programming in general. 

The socket module is low-level, it's only a thin wrapper for what your 
OS offers. Twisted would be a higher-level framework. IMO there's 
nothing wrong with using the low-level module if you want to learn 
socket programming anyway :-)

> Any good references for learning about
> this stuff, [...]

Sorry, not that I knew of. There is a (very short) Python Socket 
Programming Tutorial, but it only covers the very basics. Probably there 
is some good material out there for doing socket programming in C which 
you could easily map to Python, because the concepts and even the names 
of the functions are pretty much the same.

-- Gerhard





More information about the Python-list mailing list