def main(): f = Factory() # start the factory f.protocol = ChatClient #start the chat client f.clients = [] print('Listening on 8000...') reactor.listenTCP(8000, f) # listen on the port reactor.run() # run the reactor
def message(self, message): self.transport.write(message + '/n') factory = Factory() factory.protocol = IphoneChat factory.clients = reactor.listenTCP( 12345, factory) #factory.clients = []reactor.listenTCP(12345, factory) print("IphoneChat server started")
def button1Click(self): #print "button1Click event handler" self.button1["background"] = "yellow" import select import sys import pybonjour name = 'gamepanel' regtype = '_gamepanel._tcp' port = 3333 ##name = sys.argv[1] ##regtype = sys.argv[2] ####port = int(sys.argv[3]) def register_callback(sdRef, flags, errorCode, name, regtype, domain): if errorCode == pybonjour.kDNSServiceErr_NoError: print 'Registered service:' print ' name =', name print ' regtype =', regtype print ' domain =', domain sdRef = pybonjour.DNSServiceRegister(name = name, regtype = regtype, port = port, callBack = register_callback) class IphoneChat(Protocol): def connectionMade(self): self.factory.clients.append(self) #print "clients are ", self.factory.clients def connectionLost(self, reason): self.factory.clients.remove(self) def dataReceived(self, data): a = data #print a if a == data: # import SendKeys SendKeys.SendKeys(a) time.sleep(1) # reactor.run(installSignallHandlers=True) def message(self, message): self.transport.write(message) factory = Factory() factory.protocol = IphoneChat factory.clients = [] reactor.listenTCP(3333, factory) self.button1["background"] = "green"
def run(self): global factory factory = Factory() factory.clients = [] factory.protocol = LightServer reactor.listenTCP(7002, factory) global connections connections = [] reactor.run(installSignalHandlers=False)
def serverf(): factory = Factory() #socketT = IphoneChat() #socketT.sbutton(self.richTextCtrl1) #factory.protocol = module1.SocketT factory.protocol = With factory.clients = [] reactor.listenTCP(8001, factory) reactor.run()
def button1Click(self): #print "button1Click event handler" self.button1["background"] = "yellow" import select import sys import pybonjour name = 'gamepanel' regtype = '_gamepanel._tcp' port = 3333 ##name = sys.argv[1] ##regtype = sys.argv[2] ####port = int(sys.argv[3]) def register_callback(sdRef, flags, errorCode, name, regtype, domain): if errorCode == pybonjour.kDNSServiceErr_NoError: print 'Registered service:' print ' name =', name print ' regtype =', regtype print ' domain =', domain sdRef = pybonjour.DNSServiceRegister(name=name, regtype=regtype, port=port, callBack=register_callback) class IphoneChat(Protocol): def connectionMade(self): self.factory.clients.append(self) #print "clients are ", self.factory.clients def connectionLost(self, reason): self.factory.clients.remove(self) def dataReceived(self, data): a = data #print a if a == data: # import SendKeys SendKeys.SendKeys(a) time.sleep(1) # reactor.run(installSignallHandlers=True) def message(self, message): self.transport.write(message) factory = Factory() factory.protocol = IphoneChat factory.clients = [] reactor.listenTCP(3333, factory) self.button1["background"] = "green"
def main(): server = Server() f = Factory() # f.client_host = f.protocol = WebClient f.clients = [] f.server = server reactor.listenTCP(8080, f) print 'Listening on port', 8080 reactor.run()
def main(): # Run ROS node rospy.init_node('tablet_server') # Start the server/reactor loop factory = Factory() factory.protocol = RobotComm factory.clients = [] reactor.listenTCP(11411, factory) reactor.run() rospy.spin()
def main(args): global node arg = parse_arguments(args) port = arg.udp_port if arg.known_ip and arg.known_port: known_nodes = [(arg.known_ip, int(arg.known_port))] elif arg.config_file: known_nodes = [] f = open(arg.config_file, 'r') lines = f.readlines() f.close() for line in lines: ip_address, udp_port = line.split() known_nodes.append((ip_address, int(udp_port))) else: known_nodes = None # Set up SQLite-based data store if os.path.isfile('/tmp/dbFile%s.db' % sys.argv[1]): os.remove('/tmp/dbFile%s.db' % sys.argv[1]) data_store = SQLiteDataStore(dbFile = '/tmp/db_file_dht%s.db' % port) # Generate the Key from the peer profile r = requests.get('http://localhost:5000/api/profile') val = cStringIO.StringIO(str(r.text)) pear_profile = numpy.loadtxt(val) KEY = str(lsh(pear_profile)) # Bit of a hack. But this return the IP correctly. Just gethostname # sometimes returns 127.0.0.1 # VALUE = ([l for l in ([ip for ip in # socket.gethostbyname_ex(socket.gethostname())[2] if not # ip.startswith("127.")][:1], [[(s.connect(('8.8.8.8', 53)), # s.getsockname()[0], s.close()) for s in # [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]]) # if l][0][0]) # The real setup should use the following to get external IP. I am # using the one above since I use docker VALUE = urllib.urlopen('http://ip.42.pl/short').read().strip('\n') factory = Factory() factory.protocol = PeARSearch factory.clients = [] node = EntangledNode(udpPort=int(port), dataStore=data_store) node.joinNetwork(known_nodes) reactor.callLater(0, storeValue, KEY, VALUE, node) reactor.listenTCP(8080, factory) print "Starting the DHT node..." reactor.addSystemEventTrigger('before','shutdown', cleanup, KEY, node) reactor.run()
def twistedServer(): def RaspberryLight(Protocol): def connectionMade(self): #self.transport.write("""connected""") self.factory.clients.append(self) print "clients are ", self.factory.clients def connectionLost(self, reason): print "connection lost ", self.factory.clients self.factory.clients.remove(self) def dataReceived(self, data): global reset msg = "" ## if (data == 'P7H'): ## msg = "Pin 7 is now High" ## GPIO.output(7, True) ## ## elif (data == 'P7L'): ## msg = "Pin 7 is now Low" ## GPIO.output(7, False) if (data == 'test'): msg = "YAY THE PHONE SENT A MESSAGE as;dfjasl;ldjflkasdjfasjdflsajflksajdlfjasdkfjas;l" elif (data == 'reset door'): reset = True print "reset door" print msg factory = Factory() factory.protocol = RaspberryLight factory.clients = [] reactor.listenTCP(7777, factory) print "RaspberryLight server started" reactor.run()
def startService(textbuffer, port, welcome, statusbar): addText(textbuffer, APP_NAME, LOG_INFO) addText(textbuffer, _("Version ") + APP_VERSION, LOG_INFO) addText(textbuffer, _("Attempting to start server at port ") + str(port) + "\n", LOG_INFO) addText(textbuffer, _("Creating Factory"), LOG_INFO) factory = Factory() factory.protocol = RPG factory.textbuffer = textbuffer factory.statusbar = statusbar factory.clients = [] addText(textbuffer, _("Saving welcome message..."), LOG_INFO) factory.welcome = welcome f = open(PATH_WELCOME_MSG, "w") f.write(welcome) f.close() addText(textbuffer, _("Setting up Users datastructure"), LOG_INFO) factory.users = Users() addText(textbuffer, _("Listening for incoming connections..."), LOG_INFO) reactor.listenTCP(port, factory) reactor.run()
fclient.transport.write(msg + "^") return def hostIPaddress(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("gmail.com", 80)) myhostip = s.getsockname()[0] s.close() return myhostip except: print "Internet disconnected?" return 0 if __name__ == "__main__": myhostip = hostIPaddress() if not myhostip: sys.exit() factory = Factory() factory.protocol = Server factory.clients = [] # clients list factory.host = None PORT = 50000 # port of the server reactor.listenTCP(PORT, factory) print "[ Server info ]\nServer IP : %s\nPort : %d" % (myhostip, PORT) print "Server is now running.\nPress [ Ctrl-c ] to close the server." reactor.run()
content = a[1].rstrip() msg = "" if command == "iam": self.name = content msg = self.name + " has joined" elif command == "msg": msg = self.name + ": " + content elif command == "nix": msg = nix.search(content) print msg for c in self.factory.clients: c.message(msg) def message(self, message): self.transport.write(message + '\n') factory = Factory() factory.protocol = IphoneChat factory.clients = [] reactor.listenTCP(80, factory) print "Iphone Chat server started" reactor.run()
self.factory.clients.remove(self) def dataReceived(self, data): a = data.split(':') print a if len(a) > 1: command = a[0] content = a[1] msg = "" if command == "iam": self.name = content msg = self.name + " has joined" elif command == "msg": msg = self.name + ": " + content print msg for c in self.factory.clients: c.message(msg) def message(self, message): self.transport.write(message + '\n') factory = Factory() factory.protocol = IphoneChat factory.clients = [] reactor.listenTCP(880, factory) print "Iphone Chat server started" reactor.run()
for fclient in self.factory.clients: if fclient.transport.getPeer().host == spl[1]: fclient.transport.write(msg+"^") return def hostIPaddress(): try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("gmail.com",80)) myhostip = s.getsockname()[0] s.close() return myhostip except: print "Internet disconnected?" return 0 if __name__ == "__main__": myhostip = hostIPaddress() if not myhostip: sys.exit() factory = Factory() factory.protocol = Server factory.clients = [] # clients list factory.host = None PORT = 50000 # port of the server reactor.listenTCP(PORT, factory) print "[ Server info ]\nServer IP : %s\nPort : %d" %(myhostip, PORT) print "Server is now running.\nPress [ Ctrl-c ] to close the server." reactor.run()
def main(): f = Factory() f.protocol = Play f.clients = [] reactor.listenTCP(8000, f) reactor.run()
for c in self.factory.clients: c.message( msg ) # broadcast the message to all clients ## use the "message" mthd right below def message(self, message): # "message" mthd implm self.transport.write( message + '\n' ) # IMPORTANT : use of the '\n' char so the socket detects when the message transmission has completed. factory = Factory() # the factory handles connections ## ## added to to keep track of clients factory.clients = [ ] # initialise the array of clients as empty right after the line creating the factory ## #assign our class as the protocol of our factory factory.protocol = IphoneChat # assign IphoneChat protocol to factory reactor.listenTCP(80, factory) # implementation of a reactor pattern # > Uses port 80 cuz open by default ( as standard port for http conns) # > allow real-device-app testing wirelessly without modifying settings of the router print "Iphone Chat Server Started" reactor.run() # run the server
logging.info("Connection lost") self.factory.clients.remove(self) self.factory.ips.remove(self.ip) def dataReceived(self, data): logging.debug("Spreading "+str(len(data))+" bytes to "+str(len(self.factory.clients))+" clients") for p in self.factory.clients: if p != self: p.transport.write(data) clients = [] ips = [] f_tcp = Factory() f_tcp.protocol = Client f_tcp.clients = clients f_tcp.ips = ips from twisted.python import log observer = log.PythonLoggingObserver() observer.start() from twisted.application import internet, service from twisted.internet import reactor application = service.Application("orpend") # create the Application tcpService = internet.TCPServer(24142, f_tcp) # create the service tcpService.setServiceParent(application)
def connectionLost(self, reason): logging.info("Connection lost") self.factory.clients.remove(self) self.factory.ips.remove(self.ip) def dataReceived(self, data): logging.debug("Spreading " + str(len(data)) + " bytes to " + str(len(self.factory.clients)) + " clients") for p in self.factory.clients: if p != self: p.transport.write(data) clients = [] ips = [] f_tcp = Factory() f_tcp.protocol = Client f_tcp.clients = clients f_tcp.ips = ips from twisted.python import log observer = log.PythonLoggingObserver() observer.start() from twisted.application import internet, service from twisted.internet import reactor application = service.Application("orpend") # create the Application tcpService = internet.TCPServer(24142, f_tcp) # create the service tcpService.setServiceParent(application)