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
def __init__(self, parent): QObject.__init__(self) self.name = getStoredName() or DEFAULT_NAME self.guid = getStoredGuid() self.peers = self.getStoredPeers() self.preSendRegistrations = {} self.preSendRegistrationsNoCrypt = {} self.handlerMap = {} self.initHandlerMap() self.startRequestListener() self.requestReceivedSignal.connect(self.requestReceived) self.discoveryManger = UDPDiscovery() self.discoveryManger.peerDiscovered.connect(self.peerDiscovered) self.discoveryManger.peerDiscovered.connect(self.peerDiscovered) self.showMessageBox.connect(self.showMessageBoxSlot) self.discoveryManger.startDiscoveryServer() self.parent = parent self.continueSend.connect(self.continueSendSlot)