Hi,
I have a strange behavior.
I open network connection, and when I got a resetConnectionAvailable, I close connection…
But in the next loop, resetConnectionAvailable give again the connection to close, again and again.
I think I missed something, but what?
Initialization of network:
def __init__(self):
instance=self
networkmessage()
self.listOfUser=[]
self.cManager = QueuedConnectionManager()
self.cListener = QueuedConnectionListener(self.cManager, 0)
self.cReader = QueuedConnectionReader(self.cManager, 0)
self.cWriter = ConnectionWriter(self.cManager,0)
self.Connections = {}
self.activeConnections=[] # We'll want to keep track of these later
port_address=9099 #No-other TCP/IP services are using this port
backlog=1000 #If we ignore 1,000 connection attempts, something is wrong!
self.tcpSocket = self.cManager.openTCPServerRendezvous(port_address,backlog)
self.cListener.addConnection(self.tcpSocket)
taskMgr.add(self.tskListenerPolling,"Poll the connection listener",-39)
taskMgr.add(self.tskReaderPolling,"Poll the connection reader",-40)
taskMgr.add(self.tskNetworkMessage,"Poll the messages",-38)
Polling the network:
def tskListenerPolling(self,taskdata):
"""
Listener on connexion
"""
if self.cListener.newConnectionAvailable():
rendezvous = PointerToConnection()
netAddress = NetAddress()
newConnection = PointerToConnection()
if self.cListener.getNewConnection(rendezvous,netAddress,newConnection):
newConnection = newConnection.p()
newConnection.setNoDelay(True)
self.activeConnections.append(newConnection) # Remember connection
self.cReader.addConnection(newConnection) # Begin reading connection
self.Connections[str(newConnection.this)] = rendezvous
if self.cManager.resetConnectionAvailable():
conn=PointerToConnection()
self.cManager.getResetConnection(conn)
c=conn.p()
print "network::tskListenerPolling removing " + str(c)
print "network::tskListenerPolling self.activeConnections.count(c) " + str(self.activeConnections.count(c))
if self.activeConnections.count(c)>0:
self.activeConnections.remove(c)
usrToDelete=None
for usr in self.listOfUser:
if usr.getConnexion()==c:
usrToDelete=usr
if usrToDelete!=None:
#~ usrToDelete.saveToBDD()
usrToDelete.destroy()
for usr in self.listOfUser:
if usr!=usrToDelete:
networkmessage.instance.addMessage(C_USER_OUTGOING,str(usrToDelete.getId()),usr.getConnexion())
if usrToDelete!=None:
if self.listOfUser.index(usrToDelete)>=0:
self.listOfUser.remove(usrToDelete)
if self.Connections.has_key(str(c)):
del self.Connections[str(c)]
self.cReader.removeConnection(c)
self.cManager.closeConnection(c)
The output:
network::tskListenerPolling removing <libpanda.Connection object at 0x03C5D908>
network::tskListenerPolling self.activeConnections.count(c) 1
network::tskListenerPolling removing <libpanda.Connection object at 0x03C4DE18>
network::tskListenerPolling self.activeConnections.count(c) 0
network::tskListenerPolling removing <libpanda.Connection object at 0x03C4DE18>
network::tskListenerPolling self.activeConnections.count(c) 0
network::tskListenerPolling removing <libpanda.Connection object at 0x03C4DE48>
network::tskListenerPolling self.activeConnections.count(c) 0
network::tskListenerPolling removing <libpanda.Connection object at 0x03C4DE18>
network::tskListenerPolling self.activeConnections.count(c) 0
network::tskListenerPolling removing <libpanda.Connection object at 0x03C4DE48>
network::tskListenerPolling self.activeConnections.count(c) 0
Thank you