Stored NetAddress "resetting" when using udp

Panda 1.8.0 on arch linux

I’m trying to use a dict to map netaddresses to player entities to map clients to players. However the netaddress in the dictionary gets reset to Any suggestion how to stop this, or a better way to do virtual connections for udp?

The pseudocode:

class NetworkSystem(sandbox.EntitySystem):
    def init(self, port=1999, backlog=1000, compress=False):
        self.cManager = QueuedConnectionManager()
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cWriter = ConnectionWriter(self.cManager, 0)
        self.udpSocket = self.cManager.openUDPConnection(self.port)
        self.activeConnections = {}

    def run(self):
        if self.cReader.dataAvailable():
            datagram = NetDatagram()  
            if self.cReader.getData(datagram):
                myIterator = PyDatagramIterator(datagram)
                msgID = myIterator.getUint8()
                if msgID == protocol.LOGIN:
                    self.activeConnections[datagram.getAddress()] = Player()
                elif msgID == protocol.MOVE:
                    print self.activeConnections

And activeConnections list { player}

Thanks for any help!


NetDatagram.getAddress() returns a reference to its own internal NetAddress; when the NetDatagram goes away, the NetAddress destructs. To avoid this, make a copy when you store the address:

addr = NetAddress(datagram.getAddress().getAddr())
self.activeConnections[addr] = Player() 

The key thing is wrapping the return value of datagram.getAddress() in a new NetAddress constructor.


Thank you sir

Hey, it’s good to see you back on the forum again David.
I hope Disney hasn’t been working you too hard! :stuck_out_tongue:

I’m certainly busy, but no complaints. :slight_smile: