本文整理汇总了Python中panda3d.core.QueuedConnectionReader.removeConnection方法的典型用法代码示例。如果您正苦于以下问题:Python QueuedConnectionReader.removeConnection方法的具体用法?Python QueuedConnectionReader.removeConnection怎么用?Python QueuedConnectionReader.removeConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.core.QueuedConnectionReader
的用法示例。
在下文中一共展示了QueuedConnectionReader.removeConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TCP
# 需要导入模块: from panda3d.core import QueuedConnectionReader [as 别名]
# 或者: from panda3d.core.QueuedConnectionReader import removeConnection [as 别名]
#.........这里部分代码省略.........
def tcpListenerTask(self, task):
"""
Accept new incoming connection from clients, related to TCP
"""
# Handle new connection
if self.tcpListener.newConnectionAvailable():
rendezvous = PointerToConnection()
netAddress = NetAddress()
newConnection = PointerToConnection()
if self.tcpListener.getNewConnection(rendezvous, netAddress, newConnection):
newConnection = newConnection.p()
# Tell the reader about the new TCP connection
self.tcpReader.addConnection(newConnection)
# Handle the connection depending on persistent or not
if self.core.server.isPersistent:
self.core.handleConnection(generateUUID(), newConnection, netAddress)
else:
self.core.createPlayerObject(generateUUID(),newConnection, netAddress)
print ("Server: New Connection from -", str(netAddress.getIpString()))
else:
print ("Server: Connection Failed from -", str(netAddress.getIpString()))
return Task.cont
def tcpReaderTask(self, task):
"""
Handle any data from clients by sending it to the Handlers.
"""
while 1:
(datagram, data, opcode) = self.tcpNonBlockingRead(self.tcpReader)
if opcode is MSG_NONE:
# Do nothing or use it as some 'keep_alive' thing.
break
else:
# Handle it
self.core.packetManager.handlePacket(opcode, data, datagram.getAddress())
return Task.cont
# TCP NonBlockingRead??
def tcpNonBlockingRead(self, qcr):
"""
Return a datagram collection and type if data is available on
the queued connection udpReader
"""
if self.tcpReader.dataAvailable():
datagram = NetDatagram()
if self.tcpReader.getData(datagram):
data = DatagramIterator(datagram)
opcode = data.getUint8()
else:
data = None
opcode = MSG_NONE
else:
datagram = None
data = None
opcode = MSG_NONE
# Return the datagram to keep a handle on the data
return (datagram, data, opcode)
# TCP Disconnection Handler
def tcpDisconnectionHandler(self, task):
# Check for resets
if self.tcpManager.resetConnectionAvailable():
resetConnection = PointerToConnection()
self.tcpManager.getResetConnection(resetConnection)
for client in self.core.server.clients:
if self.core.server.clients[client].connection == resetConnection.p():
del self.core.server.clients[client]
self.tcpReader.removeConnection(resetConnection.p())
print ("Removed Connection:", resetConnection.p())
print ('Current Clients:', self.core.server.clients)
break
return Task.cont
def sendPacket(self, _pkt, _connection):
self.tcpWriter.send(_pkt, _connection)
def sendBroadcast(self, _pkt, _skipif=None):
for client in self.serverManager.clients:
if _skipif == client:
pass
else:
conn = self.serverManager.clients[client].connection
self.tcpWriter.send(_pkt, conn)
示例2: __init__
# 需要导入模块: from panda3d.core import QueuedConnectionReader [as 别名]
# 或者: from panda3d.core.QueuedConnectionReader import removeConnection [as 别名]
class NetworkManager:
def __init__(self):
print "Network Manager Started"
def connection_open(self):
self.cManager = QueuedConnectionManager()
self.cReader = QueuedConnectionReader(self.cManager, 0)
self.cWriter = ConnectionWriter(self.cManager,0)
self.activeConnections=[] # We'll want to keep track of these later
self.cListener = QueuedConnectionListener(self.cManager, 0)
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)
print "Network Connection Opened"
taskMgr.add(self.tskListenerPolling,"Poll the connection listener",-39)
taskMgr.add(self.tskReaderPolling,"Poll the connection reader",-40)
def connection_close(self):
for aClient in self.activeConnections:
self.cReader.removeConnection(aClient)
self.activeConnections=[]
# close down our listener
self.cManager.closeConnection(self.tcpSocket)
print "Network Connection Closed"
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
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):
if base.client == True:
self.client_processing(datagram)
else:
self.server_processing(datagram)
return Task.cont
def server_messager(self,msg,args=[]):
if msg == "map_set":
order = PyDatagram()
order.addUint16(MAP_SET)
order.addInt32(args[0])
self.send_package(order)
elif msg == "client_update":
order = PyDatagram()
order.addUint16(CLIENT_INIT_UPDATE)
order.addString(args[0])
order.addString(args[1])
order.addInt32(args[2])
order.addInt32(args[3])
self.send_package(order)
elif msg == "chat_send":
r = args[0][0]
g = args[0][1]
b = args[0][2]
order = PyDatagram()
order.addUint16(SERVER_CHAT)
order.addInt32(r)
order.addInt32(g)
order.addInt32(b)
order.addString(args[1])
self.send_package(order)
base.menu_manager.menus["mp-game"].chat_add((r,g,b,1),args[1])
elif msg == "ready_button":
order = PyDatagram()
order.addUint16(SERVER_READY)
order.addInt32(args[0])
order.addInt32(args[1])
self.send_package(order)
base.menu_manager.menus["mp-game"].obj_list[args[0]]["indicatorValue"]=args[1]
base.menu_manager.menus["mp-game"].start_game_check()
elif msg == "server_loaded":
order = PyDatagram()
order.addUint16(SERVER_LOADED)
self.send_package(order)
elif msg == "all_loaded":
order = PyDatagram()
order.addUint16(ALL_LOADED)
self.send_package(order)
elif msg == "game_start":
order = PyDatagram()
order.addUint16(GAME_START)
self.send_package(order)
elif msg == "army_kill":
order = PyDatagram()
#.........这里部分代码省略.........