@@ -0,0 +1,3136 @@
+import socket%0Aimport errno%0Aimport Axon%0A%0Afrom Kamaelia.Internet.Selector import Selector%0Afrom Kamaelia.IPC import newReader, newWriter%0A%0Aclass UDPReceiver(Axon.Component.component):%0A    Inboxes  = %7B%22inbox%22   : %22NOT USED%22,%0A                %22control%22    : %22Recieve shutdown messages%22,%0A                %22ReadReady%22  : %22Receive messages indicating data is ready to be read from the socket%22%7D%0A%0A    Outboxes = %7B%22outbox%22          : %22Data received from the socket%22,%0A                %22signal%22          : %22Signals receiver is shutting down%22,%0A                %22_selectorSignal%22 : %22For communication to the selector%22%7D%0A%0A    def __init__(self, local_addr, local_port):%0A        super(UDPReceiver, self).__init__(self)%0A        self.local = (local_addr, local_port)%0A        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,%0A                                  socket.IPPROTO_UDP)%0A        %0A    def main(self):%0A        #TODO: Binding should handle errors gracefully%0A        self.sock.bind(self.local)%0A        self.sock.setblocking(0)%0A        selectorService, selectorShutdownService, newSelector = Selector.getSelectorServices()%0A        if newSelector:%0A            newSelector.activate()%0A        yield 1%0A%0A        # Link to the selector's %22notify%22 inbox%0A        self.link((self, %22_selectorSignal%22), selectorService)%0A        self.send(newReader(self, ((self, %22ReadReady%22), self.sock)),%0A                   %22_selectorSignal%22)%0A%0A        # TODO: Make me shutdown nicely%0A        while 1:%0A            if self.dataReady(%22ReadReady%22):%0A                self.recv(%22ReadReady%22)%0A                data = True%0A                while data:%0A                    data = self.safeRecv(1024)%0A                    if data:%0A                        self.send(data, %22outbox%22)%0A            if not self.anyReady():%0A                self.pause()%0A            yield 1%0A%0A    def safeRecv(self, size):%0A        try:%0A            data = self.sock.recvfrom(size)%0A            if data:%0A                return data%0A        except socket.error, socket.msg:%0A            (errorno, errmsg) = socket.msg.args%0A            if errorno == errno.EAGAIN or errorno == errno.EWOULDBLOCK:%0A                self.send(newReader(self, ((self, %22ReadReady%22), self.sock)),%0A                          %22_selectorSignal%22)%0A        return None%0A%0Aclass UDPSender(Axon.Component.component):%0A    def __init__(self, receiver_addr, receiver_port):%0A        super(UDPSender, self).__init__(self)%0A        self.receiver = (receiver_addr, receiver_port)%0A        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,%0A                                  socket.IPPROTO_UDP)%0A%0A    def main(self):%0A        selectorService, selectorShutdownService, newSelector = Selector.getSelectorServices()%0A        if newSelector:%0A            newSelector.activate()%0A        self.link((self, %22_selectorSignal%22), selectorService)%0A        self.send(newWriter(self, ((self, %22WriteReady%22), self.sock)),%0A                  %22_selectorSignal%22)%0A        %0A        # TODO: Make me shutdown nicely%0A        while 1:%0A            #TODO: Write me :D%0A            pass%0A            %0A%0A                    %0Aif __name__ == %22__main__%22:%0A    UDPReceiver(%22127.0.0.1%22, 2000).run()%0A

copy for playing