def showIP(self): if util.checkConnect(self._config["interface"]): self.ip = util.getIP(self._config["interface"]) self.ui.ipLE.setText(self.ip) self.showFlows() self.timer = QTimer() self.timer.timeout.connect(self.showFlows) self.timer.start(self._config["checkDelay"]) else: self.ip = None self.ui.imgL.setPixmap(self.deadPic) self.ui.flowsL.setText("\"{0}\" isn't connect".format(self._config["interface"]))
def main(): serverHost = raw_input('Server Host: ') if not serverHost: serverHost = util.getIP() else: serverHost = socket.gethostbyname(serverHost) serverPort = input('Server Port: ') address = (serverHost, serverPort) client = ClientSocket(address) print 'Connecting to server on %s:%s' % (serverHost, serverPort) client.serve_forever()
reactor.callLater(1, self.addPortMapping, port, exPort) def _addPortMapping(self, port, exPort): d = self.upnp.addPortMapping(port, exPort) if d[0]: self.portIsForwarded(port, exPort) else: self.forwardFailed(port, exPort) def portIsAllreadyForwarded(self, port, exPort): self.log.warning('port %d is allready forwarded to %d', exPort, port) self.parent.portIsAllreadyForwarded(port, exPort) def portIsForwarded(self, port, exPort): #self.ports.append(port) self.log.info('port %d is forwarded to port %d', exPort, port) self.parent.portForwarded(port, exPort) def forwardFailed(self, port, exPort): self.log.error("port %d can't be forwarded to port %d", exPort, port) self.parent.forwardFailed(port, exPort) if __name__ == '__main__': u = UPNP() ip = util.getIP()[0] u.startUpnp(ip) reactor.callLater(3, u.addPortMapping, 50000, 50001) reactor.callLater(6, u.addPortMapping, 50004, 50005) reactor.run()
self.wfile.write('**SERVER** '+room+'\n') continue self.sendall(line) def sendall(self, data): for nickname in connections: if nickname == self.nickname: continue message = self.nickname+': '+data+'\n' if '**SERVER**' not in data else data+'\n' connections[nickname].wfile.write(message) def Room(self): room = 'Room: ' for nickname in connections: room += nickname+', ' return room if __name__ == '__main__': # Port 0 means to select an arbitrary unused port host, port = raw_input('IP Address (or hostname): '), input('Port: ') if not host: host = util.getIP() else: host = socket.gethostbyname(host) server = SocketServer.ThreadingTCPServer((host, port), ThreadedTCPRequestHandler) print 'Waiting for clients on %s:%s...' % (host, port) server.serve_forever()