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 0.0.0.0. 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.cReader.addConnection(self.udpSocket)
        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 {0.0.0.0: player}

Thanks for any help!

[/code]

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.

David

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: