looking for UDP package, network programming guidance

T

Tom Plunket

Hey all-

A friend of mine has built this interesting (to me) bit of
hardware that's intended to communicate with a PC over ethernet.
The hardware has an OS written in C, and has some PC-side testing
software written in Delphi, all of which I have access to. The
hardware communicates with the PC via UDP.

I've been working on porting the PC "test" software to Python so
that 1) I understand the code, 2) don't need to go buy Delphi to
help this guy out, and 3) learn enough about network programming
to write the actual application interface software for off-the-
shelf software to use this hardware. I spent a bunch of hours
one night learning everything I needed to about wxPython to get a
not-so-fancy but needs-a-lot-of-different-UI-elements test app UI
running, but now the stumbling block comes up that Python doesn't
seem to have any UDP handling built into its distribution.

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?

Additionally, the networking protocol is a fixed format packed
bytes sort of thing; is it easy enough in Python (with Twisted)
to read bytes off of the stream and then decide what to do with
them? (I'm a Python newbie but somewhat of a C++ pro.)

Finally, I'm also somewhat of a babe in the woods with network
programming in general. Any good references for learning about
this stuff, something that goes over issues of robustness, error
handling strategies, and so forth? It'd be best if anything had
"tutorials" written in Python, of course. ;)

thanks,
-tom!
 
S

Sean 'Shaleh' Perry

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.

W. Richard Stevens' "UNIX Network Programming" covers sockets in depth and is
one of the authoritative texts on the subject.

Yes, it is C. However the sockets API pretty much works the same in every
language.
 
T

Tom Plunket

Tom said:
...now the stumbling block comes up that Python doesn't seem to
have any UDP handling built into its distribution.


Thanks a lot for the pointers, gang. Hopefully I can get
something up and running in the next couple of days (or rather,
the next time I have a couple of uninterrupted hours for this
task), so these pointers will send me in the right direction.

I definitely like the idea of a lower level solution, so this is
nice. For whatever reason, my web search turned up info related
only to win32all, so I assumed... :)

Anyway, off to get this going. :)


-tom!
 
M

Moshe Zadka

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@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.]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top