Simple UDP server

James Mills prologic at
Thu Sep 11 00:00:41 CEST 2008


You may consider using pymills
to simplify writing your UDP server
and just concentrating on the
behavior of the system.

You can get a copy of the
latest development branch
by cloning it with Mercurial:

hg clone

There is an example UDP Server
in examples/net/ but I'll paste
it here for your reference.

Note, as stated before, UDP is a connectionless
protocol (Datagram), concurrency doesn't apply.
Also note, technically UDP doesn't guarantee
reliability or the order of packets, however the
reality is, it doesn't give you any feedback. You
have to handle this yourself.

Have fun,


#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set sw=3 sts=3 ts=3

from pymills import event
from pymills.event import *
from import UDPServer

class EchoServer(UDPServer):

   def onCONNECT(self, sock, host, port):
      print "New connection: %s:%d" % (host, port)

   def onDISCONNECT(self, sock):
      print "Disconnection: %s" % sock

   def onREAD(self, sock, line):
      line = line.strip()
      print "%s: %s" % (sock, line)

   def onERROR(self, sock, msg):
      print "ERROR (%s): %s" % (sock, msg)

def main():
   server = EchoServer(1234)
   event.manager += server

   while True:
      except KeyboardInterrupt:

if __name__ == "__main__":

On Thu, Sep 11, 2008 at 5:33 AM, Tzury Bar Yochay
<Afro.Systems at> wrote:
>> Transmitting large binary data over UDP? That makes only sense for few
>> applications like video and audio streaming. UDP does neither guarantee
>> that your data is received nor it's received in order. For example the
>> packages A, B, C, D might be received as A, D, B (no C).
>> Can your protocol handle missing packages and out of order packages?
> I intend of using it for audio transmission and don't care about lose
> or out of order.
> --

-- "Problems are solved by method"

More information about the Python-list mailing list