本文整理汇总了Python中pandac.PandaModules.QueuedConnectionReader.removeConnections方法的典型用法代码示例。如果您正苦于以下问题:Python QueuedConnectionReader.removeConnections方法的具体用法?Python QueuedConnectionReader.removeConnections怎么用?Python QueuedConnectionReader.removeConnections使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandac.PandaModules.QueuedConnectionReader
的用法示例。
在下文中一共展示了QueuedConnectionReader.removeConnections方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Server
# 需要导入模块: from pandac.PandaModules import QueuedConnectionReader [as 别名]
# 或者: from pandac.PandaModules.QueuedConnectionReader import removeConnections [as 别名]
class Server(DirectObject):
def __init__(self):
self.cManager = QueuedConnectionManager()
self.cListener = QueuedConnectionListener(self.cManager, 0)
self.cReader = QueuedConnectionReader(self.cManager, 0)
self.cWriter = ConnectionWriter(self.cManager,0)
self.activeConnections = [] # Keeps tracks of active connections
#Set up the connection
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)
self.setTaskManagers() #Set the Managers
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) # Remember connection
self.cReader.addConnection(newConnection) # Begin reading connection
self.broadCast(newConnection) #Broadcasts the Server Message
return Task.cont
def tskReaderPolling(self,taskdata):
if self.cReader.dataAvailable():
datagram = NetDatagram() # catch the incoming data in this instance
# Check the return value; if we were threaded, someone else could have
# snagged this data before we did
if self.cReader.getData(datagram):
myProcessDataFunction(datagram)
return Task.cont
def setTaskManagers(self):
taskMgr.add(self.tskListenerPolling,"Poll the connection listener",-39)
taskMgr.add(self.tskReaderPolling,"Poll the connection reader",-40)
'''
Terminate all connections.
'''
def terminateAllConnection(self):
for aClient in self.activeConnections:
self.cReader.removeConnections(aClient)
self.activeConnections = []
#Close our listener
self.cManager.closeConnection(self.tcpSocket)
'''
Terminate a connection.
'''
def terminateConnection(self, aClient):
self.cReader.removeConnections(aClient)
'''
PyDatagram for messages
Arguments: message must be a string
'''
def messageData(self, message):
messDat = PyDatagram()
messDat.addUint8(PRINT_MESSAGE)
messDat.addString(message)
return messDat
'''
Broadcast Server Message
'''
def broadCast(self, aClient):
message = self.messageData("Welcome to BaziBaz's Server\nConnection has been estabilished\n")
self.cWriter.send(message, aClient)