Example #1
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
Example #2
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