import msgpack
import logging as log

from PySide import QtCore, QtNetwork


class TestServer(QtCore.QObject):

    ready_to_read = QtCore.Signal()

    def __init__(self):
        super(TestServer, self).__init__()
        self.socket = None
        self.timer = None

    def init_socket(self):
        self.socket = QtNetwork.QUdpSocket(self)
        #self.socket.bind(QtNetwork.QHostAddress.LocalHost, 3020)
        self.socket.readyRead.connect(self.read_datagrams)
        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.demo_write)
        self.timer.start(100)

    @QtCore.Slot()
    def read_datagrams(self):
        while self.socket.hasPendingDatagrams():
            datagram = QtCore.QByteArray()
            datagram.resize(self.socket.pendingDatagramSize())
            (sender, sport) = self.socket.readDatagram(datagram.data(), datagram.size())
            log.info("Got data")

    def write(self, data):
        packed = msgpack.packb(data)
        datagram = QtCore.QByteArray(packed)
        self.socket.writeDatagram(datagram, QtNetwork.QHostAddress.LocalHost, 3020)
        print "wrote %d bytes" % datagram.size()

    @QtCore.Slot()
    def demo_write(self):
        self.write([-1, -1, -1, 255, 0, 255])

if __name__ == "__main__":
    app = QtCore.QCoreApplication(["testserver"])
    nc = TestServer()
    nc.init_socket()
    app.exec_()

@@ -19,22 +19,25 @@
 ort 
-logging as log
+signal%0Aimport sys
 %0A%0Afr
@@ -887,41 +887,8 @@
 e())
-%0A            log.info(%22Got data%22)
 %0A%0A  
@@ -1086,16 +1086,17 @@
         
+#
 print %22w
@@ -1225,34 +1225,149 @@
 %5D)%0A%0A
-if __name__ == %22__main__%22:
+def sigint_handler(signal, frame):%0A    global app%0A    app.exit()%0A%0Aif __name__ == %22__main__%22:%0A    signal.signal(signal.SIGINT, sigint_handler)
 %0A   
@@ -1413,16 +1413,49 @@
 rver%22%5D)%0A
+    print %22Press Ctrl-C to quit%22%0A
     nc =

Add sigint handler to testserver