Пример #1
0
    def setUp(self):
        #Acquire resources
        self.called = False
        self.app = QCoreApplication([])

        self.socket = QUdpSocket()

        self.server = QUdpSocket()
        self.server.bind(QHostAddress(QHostAddress.LocalHost), 45454)
Пример #2
0
    def setUp(self):
        #Acquire resources
        self.called = False
        self.app = QCoreApplication([])

        self.socket = QUdpSocket()

        self.server = QUdpSocket()
        self.server.bind(QHostAddress(QHostAddress.LocalHost), 45454)
Пример #3
0
    def __init__(self, host, port, oscprefix='', verbose=False):
        super(clientUDP, self).__init__(oscprefix=oscprefix, verbose=verbose)
        self.keepListening=True
        adr=resolv.getAddress(host, False)

        self.socket = QUdpSocket()
        self.socket.readyRead.connect(self._callback)
        self.socket.connectToHost(adr, port);
        self.remote = (adr, self.socket.peerPort())
Пример #4
0
    def __init__(self, host='', port=0, oscprefix=None, service=None, verbose=False):
        """creates a listener on any (or specified) port"""
        super(serverUDP, self).__init__(port=port, oscprefix=oscprefix, verbose=verbose)
        self.keepListening=True

        self.socket = QUdpSocket()
        if host is None or host == '':
            r=self.socket.bind(port)
        else:
            qhost=QHostAddress(host)
            r=self.socket.bind(qhost, port)
        self.socket.readyRead.connect(self._callback)
        self.remote = (host, port) ## FIXXME: 'host' is not canonicalized

        if service is not None:
            self.publisher = publisher(port=port, name=self.publishname, service=service+'._udp')
Пример #5
0
class HttpSignalsCase(unittest.TestCase):
    '''Test case for bug #124 - readDatagram signature

    QUdpSocket.readDatagram must return a tuple with the datagram, host and
    port, while receiving only the max payload size.'''

    def setUp(self):
        #Acquire resources
        self.called = False
        self.app = QCoreApplication([])

        self.socket = QUdpSocket()

        self.server = QUdpSocket()
        self.server.bind(QHostAddress(QHostAddress.LocalHost), 45454)

    def tearDown(self):
        #Release resources
        del self.socket
        del self.server
        del self.app

    def sendPackage(self):
        addr = QHostAddress(QHostAddress.LocalHost)
        self.socket.writeDatagram('datagram', addr, 45454)

    def callback(self):
        while self.server.hasPendingDatagrams():
            datagram, host, port = self.server.readDatagram(self.server.pendingDatagramSize())
            self.called = True
            self.app.quit()

    def testDefaultArgs(self):
        #QUdpSocket.readDatagram pythonic return
        # @bug 124
        QObject.connect(self.server, SIGNAL('readyRead()'), self.callback)
        self.sendPackage()
        self.app.exec_()

        self.assert_(self.called)
Пример #6
0
class HttpSignalsCase(unittest.TestCase):
    '''Test case for bug #124 - readDatagram signature

    QUdpSocket.readDatagram must return a tuple with the datagram, host and
    port, while receiving only the max payload size.'''
    def setUp(self):
        #Acquire resources
        self.called = False
        self.app = QCoreApplication([])

        self.socket = QUdpSocket()

        self.server = QUdpSocket()
        self.server.bind(QHostAddress(QHostAddress.LocalHost), 45454)

    def tearDown(self):
        #Release resources
        del self.socket
        del self.server
        del self.app

    def sendPackage(self):
        addr = QHostAddress(QHostAddress.LocalHost)
        self.socket.writeDatagram('datagram', addr, 45454)

    def callback(self):
        while self.server.hasPendingDatagrams():
            datagram, host, port = self.server.readDatagram(
                self.server.pendingDatagramSize())
            self.called = True
            self.app.quit()

    def testDefaultArgs(self):
        #QUdpSocket.readDatagram pythonic return
        # @bug 124
        QObject.connect(self.server, SIGNAL('readyRead()'), self.callback)
        self.sendPackage()
        self.app.exec_()

        self.assert_(self.called)
Пример #7
0
class clientUDP(clientAbstract.clientAbstract):
    """ OSC-client running on GOD.
    sends OSC-messages to SMi.
    receives OSC-messages from SMi (and emits signals with the data)
    """

    def __init__(self, host, port, oscprefix='', verbose=False):
        super(clientUDP, self).__init__(oscprefix=oscprefix, verbose=verbose)
        self.keepListening=True
        adr=resolv.getAddress(host, False)

        self.socket = QUdpSocket()
        self.socket.readyRead.connect(self._callback)
        self.socket.connectToHost(adr, port);
        self.remote = (adr, self.socket.peerPort())

    def __del__(self):
        self.shutdown()

    def shutdown(self):
        self.keepListening=False
        if self.socket is not None:
            try:
                self.socket.shutdown()
                self.socket.close()
            except:
                pass
        if self.addressManager is not None:
            del self.addressManager
            self.addressManager = None
        self.remote = None
        self.socket = None

    def _callback(self):
        '''Asynchronous connection listener. Receives data and passes it to OSC-addressManager.'''
        while self.socket.hasPendingDatagrams():
            datagram, sender, senderPort = self.socket.readDatagram(self.socket.pendingDatagramSize())
            if self.addressManager:
                self.addressManager.handle(datagram.data(), (sender.toString(), senderPort))

    def _send(self, data):
        if self.socket is not None and self.remote is not None:
            logging.log(1, "sending '%s' to %s" % (str(data), str(self.remote)))

            self.socket.writeDatagram(data, QHostAddress(self.remote[0]), self.remote[1])
Пример #8
0
class serverUDP(serverAbstract.serverAbstract):
    """ OSC-server running on GOD.
    sends OSC-messages to SMi.
    receives OSC-messages from SMi (and emits signals with the data)
    """

    def __init__(self, host='', port=0, oscprefix=None, service=None, verbose=False):
        """creates a listener on any (or specified) port"""
        super(serverUDP, self).__init__(port=port, oscprefix=oscprefix, verbose=verbose)
        self.keepListening=True

        self.socket = QUdpSocket()
        if host is None or host == '':
            r=self.socket.bind(port)
        else:
            qhost=QHostAddress(host)
            r=self.socket.bind(qhost, port)
        self.socket.readyRead.connect(self._callback)
        self.remote = (host, port) ## FIXXME: 'host' is not canonicalized

        if service is not None:
            self.publisher = publisher(port=port, name=self.publishname, service=service+'._udp')

    def __del__(self):
        self.shutdown()

    def shutdown(self):
        self.keepListening=False
        if self.socket is not None:
            try:
                self.socket.shutdown()
                self.socket.close()
            except:
                pass
        if self.addressManager is not None:
            del self.addressManager
            self.addressManager = None
        self.remote = None
        self.socket = None

    def _callback(self):
        '''Asynchronous connection listener. Receives data and passes it to OSC-addressManager.'''
        while self.socket.hasPendingDatagrams():
            datagram, sender, senderPort = self.socket.readDatagram(self.socket.pendingDatagramSize())
            if self.addressManager is not None:
                self.remote=(sender.toString(), senderPort)
                self.addressManager.handle(datagram.data(), self.remote)

    def _send(self, data):
        from PySide.QtNetwork import QHostAddress
        if self.socket is not None and self.remote is not None:
            logging.log(1, "serverUDP(PySide).sending '%s' to %s" % (str(data), str(self.remote)))
            self.socket.writeDatagram(data, QHostAddress(self.remote[0]), self.remote[1])

    def getPort(self):
        return self.socket.localPort()