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 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 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 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): # pkg = [] pkg = self._processData(datagram) tmpaddr = datagram.getAddress() addr = NetAddress() addr.setHost(tmpaddr.getIpString(), tmpaddr.getPort()) pkg[ADDR] = addr data.append(pkg) return data