Object Oriented Network Code - reply to specific client?

I’ve been trying to work with a client / server model, and it’s got a few rough spots for me. Specifically, I’ve been playing with this code example, “Object Oriented Networking Code” at [Object Oriented Networking Code with Panda3D Foundation).

This code sends any client reply back to ALL clients. I want it to send code back to a SPECIFIC client, the one who sent data originally.

But the connection object (usually named con) is buried in the Server.py class file, and doesn’t appear to exist in the instance that’s in the test_server.py file. If I’m wanting to process an incoming datagram and reply to the sender, how do I do that? How can the above code sample be rewritten to reply only to the client that sent the data?

Solved!

Dictionaries can contain objects, like the connection object. So I modified the Server.py’s class getData method to this:

    def getData(self):
        data = {}
        while self.cReader.dataAvailable():
            datagram = NetDatagram()  # catch the incoming data in this instance
            if self.cReader.getData(datagram):
                con = PointerToConnection()
                con = datagram.getConnection()
                data=self.processData(datagram)
                recdConnectionID = datagram.getConnection()
                data['connectionObject'] = recdConnectionID
                recdConnectionID = recdConnectionID.this
                data['connectionID'] = str(recdConnectionID)
        return data

Now it tucks in a reference to the con object into the dataRecd dictionary. To get that in your specific server instance to send data BACK to that client only, use this:

self.server.sendData(whateverDataYouSend, dataRecd['connectionObject'])