looking for UDP package, network programming guidance

Moshe Zadka m at moshez.org
Tue Jul 8 08:45:07 CEST 2003


On Mon, 07 Jul 2003, Tom Plunket <tomas at fancy.org> 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?

It isn't the only one, but it makes it fairly easy to write UDP
servers without worrying about the irrelevant low-level details.

Here is a simple example, based on an example from the UDP howto:
'''
from twisted.internet import protocol, reactor
class UpperEcho(protocol.DatagramProtocol):
    def datagramReceived(self, data, (host, port)):
        self.transport.write(data.upper(), (host, port))

reactor.listenUDP(9999, UpperEcho())
reactor.run()
'''

Run the above in the Python interpreter, and then in a different window:

moshez at green:~$ echo hello | nc -u localhost 9999
HELLO

Granted, perhaps not the most efficient way to uppercase strings,
but hopefully I got the idea across.

Despite Twisted's "largeness", you can usually limit yourself to
the howto you're interested in, and read others only as they come
in useful.
[If you have further Twisted questions, the Twisted mailing list
is the best forum to ask in.]
-- 
Moshe Zadka -- http://moshez.org/
Buffy: I don't like you hanging out with someone that... short.
Riley: Yeah, a lot of young people nowadays are experimenting with shortness.
Agile Programming Language -- http://www.python.org/





More information about the Python-list mailing list