def tcpListenerTask(self, task): """ Accept new incoming connection from clients, related to TCP """ # Handle new connection if self.connectionManager.tcpListener.newConnectionAvailable(): rendezvous = PointerToConnection() netAddress = NetAddress() newConnection = PointerToConnection() if self.connectionManager.tcpListener.getNewConnection( rendezvous, netAddress, newConnection): newConnection = newConnection.p() self.connectionManager.tcpReader.addConnection(newConnection) clientId = generateUUID() self.connectionManager.streamMgr.clientManager.clients[newConnection] = Client(clientId, \ self.connectionManager.streamMgr.server, newConnection, netAddress) print "Server: New Connection from -", str( netAddress.getIpString()), clientId else: print "Server: Connection Failed from -", str( netAddress.getIpString()) return Task.cont
def ConnectToServer(self, serverAddress): self.fsm.request('WaitingForJoinResponse') self.log.WriteLine('Requesting to join server (%s)' % serverAddress) serverAddr = NetAddress() serverAddr.setHost(serverAddress, Globals.PORT_SERVER_LISTENER) self.dataHandler.SetServerAddress(serverAddr) self.dataHandler.SendRequestToJoinServer() self.acceptOnce(ServerJoinResponseEvent.EventName, self.OnServerJoinResponseEvent) taskMgr.doMethodLater(1.8, self.OnRequestJoinTimeout, 'serverJoinTimeout', extraArgs = [False])
def TCPPacketListenTask(self, task): if self.tcpReader.dataAvailable(): datagram = NetDatagram() if self.tcpReader.getData(datagram): data = PyDatagramIterator(datagram) ip = datagram.getAddress().getIpString() port = datagram.getAddress().getPort() peerAddr = NetAddress() peerAddr.setHost(ip, port) packetType = data.getUint8() if(packetType == Packet.PC_TCP_PACKET): self.tcpPacketController.OnPacketReceived(data, peerAddr) return task.cont
def __listenTask(self, Task): ''' This task listens for connections. When a connection is made it adds the connection to the clients list and begins listening to that connection.''' if self._cListener.newConnectionAvailable(): rendezvous = PointerToConnection() netAddress = NetAddress() newConnection = PointerToConnection() if self._cListener.getNewConnection(rendezvous,netAddress,newConnection): newConnection = newConnection.p() if newConnection not in self.connections: self.connections.append(newConnection) self._cReader.addConnection(newConnection) # Begin reading connection self._console.printNotice('Connection from %s'%netAddress.getIpString()) else: self._console.printNotice('%s: already connected'%(newConnection.getAddress().getIpString())) return Task.cont
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 UDPPacketListenTask(self, task): while self.cReader.dataAvailable(): datagram = NetDatagram() if self.cReader.getData(datagram): #print 'PACKET', datagram data = PyDatagramIterator(datagram) ip = datagram.getAddress().getIpString() port = datagram.getAddress().getPort() peerAddr = NetAddress() peerAddr.setHost(ip, port) packetType = data.getUint8() if(packetType == Packet.PC_RELIABLE_PACKET): self.reliablePacketController.OnPacketReceived(data, peerAddr) elif(packetType == Packet.PC_UNRELIABLE_PACKET): self.unreliablePacketController.OnPacketReceived(data, peerAddr) elif(packetType == Packet.PC_ENVIRONMENT_PACKET): self.dataHandler.OnDataReceived(data, peerAddr, Packet.PC_ENVIRONMENT_PACKET) return Task.cont
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 UDPPacketListenTask(self, task = None): while self.cReader.dataAvailable(): datagram = NetDatagram() if self.cReader.getData(datagram): data = PyDatagramIterator(datagram) ip = datagram.getAddress().getIpString() port = datagram.getAddress().getPort() peerAddr = NetAddress() peerAddr.setHost(ip, port) #print 'GOT UDP PACKET FROM', peerAddr.getIpString(), peerAddr.getPort() isReliable = data.getUint8() if(isReliable == Packet.PC_RELIABLE_PACKET): self.reliablePacketController.OnPacketReceived(data, peerAddr) elif(isReliable == Packet.PC_UNRELIABLE_PACKET): self.unreliablePacketController.OnPacketReceived(data, peerAddr) if(self.ClientIsConnected(peerAddr)): self.GetActiveClient(peerAddr).timestamp = GameTime.time return task.cont
def connection_polling(self, taskdata): if self.cListener.newConnectionAvailable(): rendezvous = PointerToConnection() netAddress = NetAddress() newConn = PointerToConnection() if self.cListener.getNewConnection(rendezvous, netAddress, newConn): conn = newConn.p() self.cReader.addConnection(conn) # Begin reading connection conn_id = self.client_counter logging.info("New Connection from ip:%s, conn:%s" % (conn.getAddress(), conn_id)) self.connection_map[conn_id] = conn self.client_counter += 1 message = eVV_ACK_OK(self.ip, self.port, conn_id) self.sendMessage(message, conn) return Task.cont
def listenerPoll(self, task): """ Listen for connections. """ if not self.locked: if self.cListener.newConnectionAvailable(): print "-----------------------------------" print "New connection available..." rendezvous = PointerToConnection() netAddress = NetAddress() newConnection = PointerToConnection() if self.cListener.getNewConnection(rendezvous, netAddress, newConnection): newConnection = newConnection.p() self.Connections[str(newConnection.this)] = rendezvous self.cReader.addConnection(newConnection) print "IP Address: %s" % newConnection.getAddress() print "ConnectionID: %s" % newConnection.this self.displayServerStatus() #if self.__class__.__name__ == 'LoginServer': # self.sendServerMessage('ciac', # newConnection) return Task.cont