Sign in to follow this  
sipickles

UDP message sorting

Recommended Posts

sipickles    240
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

Share this post


Link to post
Share on other sites
Antheus    2409
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this