[Twisted-Python] Sending other things than strings in UDP packets

Hi, I am working on a UDP server. I can send and recieve packets with their data in strings with no problems. However, I was wondering if there is a way to populate the data portion of the packet with data types other than strings. And to be able to stick a number of values, might be of different types, together in the same packet. I looked at PB. It is not what I need. I need a low level control on what I add to the packets I send and how I can read packets I recieve. Thanks, ib __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

On Wed, Oct 06, 2004 at 03:28:36AM -0700, Ibrahim Mubarak wrote:
UDP is a datagram transport -- it sends packets of some number of bytes with no guarantees of order or even delivery, beyond that if a packet is delivered, it will be delivered whole. All it knows about the payload of those packets is that they contain bytes. What those bytes represent is entirely up to the protocol author. You can use them to represent ascii strings, unicode characters, a series of 32-bit integers, or a combination of anything like you like, so long as you can work out how to encode it as bytes at the sender's end, and decode it at the receiver's end. The 'struct' module in the Python standard library can help a lot here: http://docs.python.org/lib/module-struct.html
I looked at PB. It is not what I need. I need a low level control on what I add to the packets I send and how I can read packets I recieve.
You're right. PB is a high-level remote object protocol built on TCP. However, its jelly and banana layers do demonstrate one (moderately complex, but flexible) approach to serialising arbitrary objects to bytes and back. It's almost certainly much more than you need for serialising data in UDP packets, though. -Andrew.

On Wed, Oct 06, 2004 at 03:28:36AM -0700, Ibrahim Mubarak wrote:
UDP is a datagram transport -- it sends packets of some number of bytes with no guarantees of order or even delivery, beyond that if a packet is delivered, it will be delivered whole. All it knows about the payload of those packets is that they contain bytes. What those bytes represent is entirely up to the protocol author. You can use them to represent ascii strings, unicode characters, a series of 32-bit integers, or a combination of anything like you like, so long as you can work out how to encode it as bytes at the sender's end, and decode it at the receiver's end. The 'struct' module in the Python standard library can help a lot here: http://docs.python.org/lib/module-struct.html
I looked at PB. It is not what I need. I need a low level control on what I add to the packets I send and how I can read packets I recieve.
You're right. PB is a high-level remote object protocol built on TCP. However, its jelly and banana layers do demonstrate one (moderately complex, but flexible) approach to serialising arbitrary objects to bytes and back. It's almost certainly much more than you need for serialising data in UDP packets, though. -Andrew.
participants (2)
-
Andrew Bennetts
-
Ibrahim Mubarak