예제 #1
0
 def listenerThread(self):
     listener = TCPSocket()
     listener.listen("0.0.0.0", 32102)
     while True:
         requestSocket = listener.accept()
         requestHandlerThread = Thread(target=self.receiverThread, args=(requestSocket,))
         requestHandlerThread.start()
예제 #2
0
 def responseListenerThread(self):
     while True:
         listenerSocket = TCPSocket()
         listenerSocket.listen("0.0.0.0", DEFAULT_DISCOVERY_PORT)
         newConnection = listenerSocket.accept()
         discoveredThread = threading.Thread(target=self.peerDiscoveredThread,
                                             args=(newConnection,))
         discoveredThread.start()
예제 #3
0
 def responseSenderThread():
     listenerSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     listenerSocket.bind(("0.0.0.0", DEFAULT_MULTICAST_PORT))
     socketSettings = struct.pack("4sL", socket.inet_aton(DEFAULT_MULTICAST_GROUP), socket.INADDR_ANY)
     listenerSocket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, socketSettings)
     while True:
         data, address = listenerSocket.recvfrom(1024)
         responder = TCPSocket()
         myName = getStoredName() or DEFAULT_NAME
         try:
             responder.connect(address[0], DEFAULT_DISCOVERY_PORT)
             responder.send((getStoredGuid() + ":" + myName).encode("utf-8"))
         except NetworkingError:
             pass
예제 #4
0
 def sendRequestToPeer(self, peer, type, data, timeout=None):
     peerSocket = TCPSocket()
     peerSocket.connect(self.peers[peer].lastKnownIP, 32102)
     self.sendRequestToSocket(peerSocket, type, data, timeout)
     return peerSocket