Networking Problems

I am running OSX 10.8.5 with P3d v 1.8.1. For some reason, I cannot get even a simple networking example to work. Here is the basis my server:

taskMgr.add(self.tskListenerPolling,"Poll the connection listener",-39)
        print "taskListenerPolling enabled - now listening on designated port"

        taskMgr.add(self.tskReaderPolling,"Poll the connection reader",-40)
        print "taskReaderPolling enabled - now scanning packets on port"

    def processDatagram(self, netDatagram): # Where the server processes incoming messages.
        print netDatagram
        myIterator = PyDatagramIterator(netDatagram)
        msgID = myIterator.getUint8()
        if msgID == self.commandMap['msg']:
            messageToPrint = myIterator.getString()
            print messageToPrint
            self.sendToAll(msgID, messageToPrint)

    def tskListenerPolling(self, taskdata):
        if self.cListener.newConnectionAvailable():
            rendezvous    = PointerToConnection()
            netAddress    = NetAddress()
            newConnection = PointerToConnection()
            if self.cListener.getNewConnection(rendezvous,netAddress,newConnection):
                newConnection = newConnection.p()
                self.activeConnections.append(newConnection)
                print 'New connection recieved - ' + str(newConnection)
                self.cReader.addConnection(newConnection)

        return Task.cont

    def tskReaderPolling(self, taskdata): # Where the server recieves incoming messages.
        if self.cReader.dataAvailable():
            datagram=NetDatagram()
            if self.cReader.getData(datagram):
                self.processDatagram(datagram)
        return Task.cont

    def sendToAll(self, command, message):
        datagram = PyDatagram()
        datagram.addUint8(command)
        datagram.addString(str(message))
        for client in self.activeConnections:
            if self.cWriter.send(datagram, client):
                print 'Sent packet to ' + str(client)
            else:
                print 'Failed sending packet to ' + str(client)

And my client:

self.cManager = QueuedConnectionManager()
        self.cListener = QueuedConnectionListener(self.cManager, 0)
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cWriter = ConnectionWriter(self.cManager, 0)
        self.connection = self.cManager.openTCPClientConnection(self.ip_address, self.port, self.timeout)

        taskMgr.add(self.recieveMessage, 'Listening for incoming data', -40)

        if self.connection:
            print 'Connected to server'
        else:
            print 'Not connected'

    def constructDatagram(self, command, string):
        datagram = PyDatagram()
        datagram.addUint8(command) # command
        datagram.addString(str(string))
        return datagram

    def sendMessage(self, string, command):
        self.cWriter.send(self.constructDatagram(self.commandMap[command], string), self.connection)

    def processDatagram(self, datagram):
        iterator = PyDatagramIterator(datagram)
        command  = iterator.getUint8()
        if command == self.commandMap['msg']:
            print self.iterator.getString()

    def recieveMessage(self, task):
        if self.cReader.dataAvailable():
            datagram = PyDatagram()
        else:
            datagram = ''
        if self.cReader.getData(datagram):
            self.processDatagram(datagram)
        return Task.cont

    def closeConnection(self):
        self.cManager.closeConnection(self.connection)

The error occurs when the client sends data to the server. For example, a datagram with the message “Test message” is sent to the server. The server, after receiving the data, prints:

Which is also supposed to send the client back the same message.

But the client receives nothing, and no errors occur (are shown/printed).
What I do know is:

  • the ‘processDatagram’ function on the client is never reached (getData() always returns false???)
  • the client’s send function works
  • all the rest of the server/client code appears to be working besides the client receive function. Or is it the server sendToAll function thats not working?

Any idea of what may be happening?