UDP message sorting

Started by
0 comments, last by Antheus 16 years, 6 months ago
Hi, I am upgrading my server, written in python using twisted.internet, to use UDP for speed. I am new to UDP but have played with TCP a fair bit. Since UDP is stateless, all messages to the server just flow in to a general queue rather than coming from connections like TCP. In python, it looks like this:

class myUDPServer(datagramProtocol):
    def datagramReceived(self, data, (ip, port)):
        print "Message from $s:%d is $s" % (ip, port, data)
        #now sort the message by ip and port to identify sender?


Python-implementation aside, am I right in thinking that I have to sort incoming messages 'manually' with UDP, based on the IP and port of the client? Or am I missing something obvious :) Thanks for the advice Si
Advertisement
Quote:Python-implementation aside, am I right in thinking that I have to sort incoming messages 'manually' with UDP, based on the IP and port of the client?


You don't need to sort, just resolve.

Usually, you'll have a per-client object associated (hash map) with each pair. When you receive a message, you look this object up, then pass it what you received.

Other approach is to use a single handler. When you receive the message, you parse it, convert/look up the ip/port pair into some internal ID you can use, then pass that to your engine. Or, you might choose to use the pair itself as identifier and pass that around.

But yes, port/ip pair is the only identifier network layer provides you. There are potential problems with uniqueness, but it is sufficient for most cases.

This topic is closed to new replies.

Advertisement