本文整理汇总了Python中pandac.PandaModules.QueuedConnectionReader.removeConnection方法的典型用法代码示例。如果您正苦于以下问题:Python QueuedConnectionReader.removeConnection方法的具体用法?Python QueuedConnectionReader.removeConnection怎么用?Python QueuedConnectionReader.removeConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandac.PandaModules.QueuedConnectionReader
的用法示例。
在下文中一共展示了QueuedConnectionReader.removeConnection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pandac.PandaModules import QueuedConnectionReader [as 别名]
# 或者: from pandac.PandaModules.QueuedConnectionReader import removeConnection [as 别名]
class LoginServer:
def __init__(self, port, backlog=1000, compress=False):
self.port = port
self.backlog = backlog
self.compress = compress
self.cManager = QueuedConnectionManager()
self.cListener = QueuedConnectionListener(self.cManager, 0)
self.cReader = QueuedConnectionReader(self.cManager, 0)
self.cWriter = ConnectionWriter(self.cManager, 0)
self.db = DataBase()
# This is for pre-login
self.tempConnections = []
# This is for authed clients
self.activeConnections = []
# Temp user dict
self.clients = {}
self.connect(self.port, self.backlog)
self.startPolling()
def connect(self, port, backlog=1000):
# Bind to our socket
tcpSocket = self.cManager.openTCPServerRendezvous(port, backlog)
self.cListener.addConnection(tcpSocket)
def startPolling(self):
taskMgr.add(self.tskListenerPolling, "serverListenTask", -40)
taskMgr.add(self.tskDisconnectPolling, "serverDisconnectTask", -39)
def tskListenerPolling(self, task):
if self.cListener.newConnectionAvailable():
rendezvous = PointerToConnection()
netAddress = NetAddress()
newConnection = PointerToConnection()
if self.cListener.getNewConnection(rendezvous, netAddress, newConnection):
newConnection = newConnection.p()
self.tempConnections.append(newConnection) # Lets add it to a temp list first.
self.cReader.addConnection(newConnection) # Begin reading connection
# Make the temp place holder then add to temp, under dataget check the temp list, if something ther do
# auth and then add to the active
return Task.cont
def tskDisconnectPolling(self, task):
while self.cManager.resetConnectionAvailable() == True:
print "disconnect"
connPointer = PointerToConnection()
self.cManager.getResetConnection(connPointer)
connection = connPointer.p()
# Remove the connection we just found to be "reset" or "disconnected"
self.cReader.removeConnection(connection)
# Remove the connection we just found to be "reset" or "disconnected"
self.cReader.removeConnection(connection)
for u in range(len(self.clients)):
if self.clients[u]["connection"] == connection:
del self.clients[u]
break
# Loop through the activeConnections till we find the connection we just deleted
# and remove it from our activeConnections list
for c in range(0, len(self.activeConnections)):
if self.activeConnections[c] == connection:
del self.activeConnections[c]
break
return Task.cont
def broadcastData(self, data):
# Broadcast data out to all activeConnections
for con in self.activeConnections:
self.sendData(data, con)
def processData(self, netDatagram):
myIterator = PyDatagramIterator(netDatagram)
return self.decode(myIterator.getString())
def getClients(self):
# return a list of all activeConnections
return self.activeConnections
def encode(self, data, compress=False):
# encode(and possibly compress) the data with rencode
return rencode.dumps(data, compress)
def decode(self, data):
# decode(and possibly decompress) the data with rencode
return rencode.loads(data)
def sendData(self, data, con):
myPyDatagram = PyDatagram()
myPyDatagram.addString(self.encode(data, self.compress))
self.cWriter.send(myPyDatagram, con)
# This will check and do the logins.
#.........这里部分代码省略.........
示例2: LoginServer
# 需要导入模块: from pandac.PandaModules import QueuedConnectionReader [as 别名]
# 或者: from pandac.PandaModules.QueuedConnectionReader import removeConnection [as 别名]
class LoginServer(ShowBase):
def __init__(self, port, backlog = 1000, compress = False):
ShowBase.__init__(self)
self.compress = compress
self.cManager = QueuedConnectionManager()
self.cListener = QueuedConnectionListener(self.cManager, 0)
self.cReader = QueuedConnectionReader(self.cManager, 0)
self.cWriter = ConnectionWriter(self.cManager,0)
self.clientdb = ClientDataBase()
if not self.clientdb.connected:
self.clientdb = None
print 'Login Server failed to start...'
else:
# This is for pre-login
self.tempConnections = []
# This is for authed clients
self.activeClients = []
# This is for authed servers
self.activeServers = []
# This is for authed chat servers
self.activeChats = []
self.connect(port, backlog)
self.startPolling()
self.taskMgr.doMethodLater(0.5, self.lobbyLoop, 'Lobby Loop')
print 'Login Server operating...'
def connect(self, port, backlog = 1000):
# Bind to our socket
tcpSocket = self.cManager.openTCPServerRendezvous(port, backlog)
self.cListener.addConnection(tcpSocket)
def startPolling(self):
self.taskMgr.add(self.tskListenerPolling, "serverListenTask", -40)
self.taskMgr.add(self.tskDisconnectPolling, "serverDisconnectTask", -39)
def tskListenerPolling(self, task):
if self.cListener.newConnectionAvailable():
rendezvous = PointerToConnection()
netAddress = NetAddress()
newConnection = PointerToConnection()
if self.cListener.getNewConnection(rendezvous, netAddress, newConnection):
newConnection = newConnection.p()
self.tempConnections.append(newConnection)
self.cReader.addConnection(newConnection)
return Task.cont
def tskDisconnectPolling(self, task):
while self.cManager.resetConnectionAvailable() == True:
connPointer = PointerToConnection()
self.cManager.getResetConnection(connPointer)
connection = connPointer.p()
# Remove the connection
self.cReader.removeConnection(connection)
# Check for if it was a client
for client in self.activeClients:
if client.connection == connection:
print 'removing client'
self.activeClients.remove(client)
break
# then check servers
for server in self.activeServers:
if server.connection == connection:
self.activeServers.remove(server)
break
# then check servers
for chat in self.activeChats:
if chat.connection == connection:
self.activeChats.remove(chat)
break
return Task.cont
def processData(self, netDatagram):
myIterator = PyDatagramIterator(netDatagram)
return self.decode(myIterator.getString())
def encode(self, data, compress = False):
# encode(and possibly compress) the data with rencode
return rencode.dumps(data, compress)
def decode(self, data):
# decode(and possibly decompress) the data with rencode
return rencode.loads(data)
def sendData(self, data, con):
myPyDatagram = PyDatagram()
myPyDatagram.addString(self.encode(data, self.compress))
self.cWriter.send(myPyDatagram, con)
# This will check and do the logins.
def auth(self, datagram):
# If in login state.
#.........这里部分代码省略.........
示例3: __init__
# 需要导入模块: from pandac.PandaModules import QueuedConnectionReader [as 别名]
# 或者: from pandac.PandaModules.QueuedConnectionReader import removeConnection [as 别名]
class Client:
def __init__(self, host, port, timeout=3000, compress=False):
self.host = host
self.port = port
self.timeout = timeout
self.compress = compress
self.cManager = QueuedConnectionManager()
self.cReader = QueuedConnectionReader(self.cManager, 0)
self.cWriter = ConnectionWriter(self.cManager, 0)
# By default, we are not connected
self.connected = False
self.connect(self.host, self.port, self.timeout)
self.startPolling()
def connect(self, host, port, timeout=3000):
# Connect to our host's socket
self.myConnection = self.cManager.openTCPClientConnection(host, port, timeout)
if self.myConnection:
self.cReader.addConnection(self.myConnection) # receive messages from server
self.connected = True # Let us know that we're connected
def startPolling(self):
taskMgr.add(self.tskDisconnectPolling, "clientDisconnectTask", -39)
def tskDisconnectPolling(self, task):
while self.cManager.resetConnectionAvailable() == True:
connPointer = PointerToConnection()
self.cManager.getResetConnection(connPointer)
connection = connPointer.p()
# Remove the connection we just found to be "reset" or "disconnected"
self.cReader.removeConnection(connection)
# Let us know that we are not connected
self.connected = False
return Task.cont
def processData(self, netDatagram):
myIterator = PyDatagramIterator(netDatagram)
return self.decode(myIterator.getString())
def getConnected(self):
# Check whether we are connected or not
return self.connected
def encode(self, data, compress=False):
# encode(and possibly compress) the data with rencode
return rencode.dumps(data, compress)
def decode(self, data):
# decode(and possibly decompress) the data with rencode
return rencode.loads(data)
def sendData(self, data):
myPyDatagram = PyDatagram()
myPyDatagram.addString(self.encode(data, self.compress))
self.cWriter.send(myPyDatagram, self.myConnection)
def getData(self):
data = []
while 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):
data.append(self.processData(datagram))
return data
示例4: __init__
# 需要导入模块: from pandac.PandaModules import QueuedConnectionReader [as 别名]
# 或者: from pandac.PandaModules.QueuedConnectionReader import removeConnection [as 别名]
class Server:
def __init__(self, port, backlog=1000, compress=False):
self.port = port
self.backlog = backlog
self.compress = compress
self.cManager = QueuedConnectionManager()
self.cListener = QueuedConnectionListener(self.cManager, 0)
self.cReader = QueuedConnectionReader(self.cManager, 0)
self.cWriter = ConnectionWriter(self.cManager,0)
self.activeConnections = [] # We'll want to keep track of these later
self.connect(self.port, self.backlog)
self.startPolling()
def connect(self, port, backlog=1000):
# Bind to our socket
tcpSocket = self.cManager.openTCPServerRendezvous(port, backlog)
self.cListener.addConnection(tcpSocket)
def startPolling(self):
taskMgr.add(self.tskListenerPolling, "serverListenTask", -40)
taskMgr.add(self.tskDisconnectPolling, "serverDisconnectTask", -39)
def tskListenerPolling(self, task):
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 tskDisconnectPolling(self, task):
while self.cManager.resetConnectionAvailable() == True:
connPointer = PointerToConnection()
self.cManager.getResetConnection(connPointer)
connection = connPointer.p()
# Remove the connection we just found to be "reset" or "disconnected"
self.cReader.removeConnection(connection)
# Loop through the activeConnections till we find the connection we just deleted
# and remove it from our activeConnections list
for c in range(0, len(self.activeConnections)):
if self.activeConnections[c] == connection:
del self.activeConnections[c]
break
return Task.cont
def broadcastData(self, data):
# Broadcast data out to all activeConnections
for con in self.activeConnections:
self.sendData(data, con)
def processData(self, netDatagram):
myIterator = PyDatagramIterator(netDatagram)
return self.decode(myIterator.getString())
def getClients(self):
# return a list of all activeConnections
return self.activeConnections
def encode(self, data, compress=False):
# encode(and possibly compress) the data with rencode
return rencode.dumps(data, compress)
def decode(self, data):
# decode(and possibly decompress) the data with rencode
return rencode.loads(data)
def sendData(self, data, con):
myPyDatagram = PyDatagram()
myPyDatagram.addString(self.encode(data, self.compress))
self.cWriter.send(myPyDatagram, con)
def getData(self):
data = []
while 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):
data.append(self.processData(datagram))
return data
示例5: Server
# 需要导入模块: from pandac.PandaModules import QueuedConnectionReader [as 别名]
# 或者: from pandac.PandaModules.QueuedConnectionReader import removeConnection [as 别名]
class Server(ShowBase):
def __init__(self):
ShowBase.__init__(self)
# Server Networking handling stuff
self.compress = False
self.cManager = QueuedConnectionManager()
self.cListener = QueuedConnectionListener(self.cManager, 0)
self.cReader = QueuedConnectionReader(self.cManager, 0)
self.cWriter = ConnectionWriter(self.cManager, 0)
self.tempConnections = []
self.unauthenticatedUsers = []
self.users = []
self.passedData = []
self.connect(9099, 1000)
self.startPolling()
self.attemptAuthentication()
self.taskMgr.doMethodLater(0.5, self.lobbyLoop, 'Lobby Loop')
def connect(self, port, backlog = 1000):
# Bind to our socket
tcpSocket = self.cManager.openTCPServerRendezvous(port, backlog)
self.cListener.addConnection(tcpSocket)
def startPolling(self):
self.taskMgr.add(self.tskListenerPolling, "serverListenTask", -40)
self.taskMgr.add(self.tskDisconnectPolling, "serverDisconnectTask", -39)
def tskListenerPolling(self, task):
if self.cListener.newConnectionAvailable():
rendezvous = PointerToConnection()
netAddress = NetAddress()
newConnection = PointerToConnection()
if self.cListener.getNewConnection(rendezvous, netAddress, newConnection):
newConnection = newConnection.p()
newConnection.setNoDelay(True)
self.tempConnections.append(newConnection) # Remember connection
self.cReader.addConnection(newConnection) # Begin reading connection
return Task.cont
def tskDisconnectPolling(self, task):
while self.cManager.resetConnectionAvailable() == True:
connPointer = PointerToConnection()
self.cManager.getResetConnection(connPointer)
connection = connPointer.p()
# Remove the connection we just found to be "reset" or "disconnected"
self.cReader.removeConnection(connection)
# remove from our activeConnections list
if connection in self.tempConnections:
self.tempConnections.remove(connection)
for user in self.unauthenticatedUsers:
if connection == user.connection:
self.unauthenticatedUsers.remove(user)
for user in self.users:
if connection == user.connection:
user.connection = None
self.passData(('disconnect', user.name), None)
return Task.cont
def broadcastData(self, data):
# Broadcast data out to all users
for user in self.users:
if user.connection:
self.sendData(data, user.connection)
def processData(self, netDatagram):
myIterator = PyDatagramIterator(netDatagram)
return self.decode(myIterator.getString())
def getUsers(self):
# return a list of all users
return self.users
def encode(self, data, compress = False):
# encode(and possibly compress) the data with rencode
return rencode.dumps(data, compress)
def decode(self, data):
# decode(and possibly decompress) the data with rencode
return rencode.loads(data)
def sendData(self, data, con):
myPyDatagram = PyDatagram()
myPyDatagram.addString(self.encode(data, self.compress))
self.cWriter.send(myPyDatagram, con)
def passData(self, data, connection):
self.passedData.append((data, connection))
def getData(self):
#.........这里部分代码省略.........
示例6: SocketServer
# 需要导入模块: from pandac.PandaModules import QueuedConnectionReader [as 别名]
# 或者: from pandac.PandaModules.QueuedConnectionReader import removeConnection [as 别名]
#.........这里部分代码省略.........
frequency = packet.get_char()
width = packet.get_int()
height = packet.get_int()
jpeg = packet.get_bool()
data = (frequency, width, height, jpeg)
camera = self.cam_mgr.getCameraById(cam_id)
logging.debug("Received VV_REQ_IMG message from conn:%s" % conn_id)
if camera and not camera.hasSession():
session = self.activeSessions[conn_id]
session.addCamera(cam_id)
camera.setSession(session, VP_BASIC, self.ip, self.port, data)
else:
if conn_id in self.activeSessions:
self.activeSessions[conn_id].newMessage(message_type, packet)
def newVPSession(self, conn, type, pipeline, conn_id, req_cam_id):
if type == VP_ADVANCED:
camera_type = -1
if pipeline == STATIC_PIPELINE:
camera_type = STATIC_CAMERA ## Change this to use a different static camera class
elif pipeline == PTZ_PIPELINE:
camera_type = ACTIVE_CAMERA
if camera_type != -1:
#cam = self.cam_mgr.getAvailableCamera(camera_type)
cam = self.cam_mgr.getRequestedCamera(camera_type, req_cam_id)
if cam:
session = VPSession(conn_id, conn, self, VP, pipeline)
session.addCamera(cam.getId())
self.activeSessions[conn_id] = session
message = eVV_VP_ACK_OK(self.ip, self.port, cam.getId())
logging.debug("Sent VV_VP_ACK_OK message to conn:%s"
% conn_id)
self.sendMessage(message, conn)
cam.setSession(session, type, self.ip, self.port)
else:
message = eVV_VP_ACK_FAILED(self.ip, self.port)
logging.debug("Sent VV_VP_ACK_FAILED message to conn:%s"
% conn_id)
self.sendMessage(message, conn)
else:
message = eVV_VP_ACK_FAILED(self.ip, self.port)
logging.debug("Sent VV_VP_ACK_FAILED message to conn:%s"
% conn_id)
self.sendMessage(message, conn)
def newSyncSession(self, conn, conn_id, vv_id):
session = SyncSession(conn_id, conn, self, SYNC)
self.sync.setSession(session, vv_id, self.ip, self.port)
self.activeSessions[conn_id] = session
message = eVV_SYNC_ACK(self.ip, self.port, vv_id)
logging.debug("Sent VV_SYNC_ACK message to conn:%s" % conn_id)
self.sendMessage(message, conn)
def sendMessage(self, message, conn):
self.cWriter.send(message, conn)
def disconnection_polling(self, taskdata):
if(self.cManager.resetConnectionAvailable()):
connectionPointer = PointerToConnection()
self.cManager.getResetConnection(connectionPointer)
lostConnection = connectionPointer.p()
for session in self.activeSessions.values():
if session.conn == lostConnection:
logging.info("Lost Connection from ip:%s, conn:%s"
%(session.client_address, session.conn_id))
conn_id = session.conn_id
if session.getSessionType() == VP:
cameras = session.getCameras()
for cam_id in cameras:
camera = self.cam_mgr.getCameraById(cam_id)
camera.clearSession()
del self.activeSessions[conn_id]
del self.connection_map[conn_id]
break
self.cManager.closeConnection(lostConnection)
return Task.cont
def toggleInfo(self):
if self.showing_info:
self.info_label.hide()
self.showing_info = False
else:
self.info_label.show()
self.showing_info = True
def exit(self):
for connection in self.connection_map.values():
self.cReader.removeConnection(connection)
self.cManager.closeConnection(self.tcpSocket)
self.tcpSocket.getSocket().Close()