def serve(self, noblock=True): self.startLoopback() self.listen() try: eventlet.serve(self.lsock, self.accept) except KeyboardInterrupt: pass
def runNonBlockingSocket(self): '''Run the nonblocking socket server. Any time a client connects to (self.host, self.PORT), recieveData is called to handle the request.''' listener = eventlet.listen( (self.host, self.PORT) ) logging.info( 'Recieving on %s, %s' % (self.host, self.PORT) ) eventlet.serve(listener, self.recieveData)
def test_raising_stopserve(self): def stopit(conn, addr): raise eventlet.StopServe() l = eventlet.listen(('localhost', 0)) # connect to trigger a call to stopit gt = eventlet.spawn(eventlet.connect, ('localhost', l.getsockname()[1])) eventlet.serve(l, stopit) gt.wait()
def start(): server = eventlet.listen(('0.0.0.0', PORT)) if DEBUG: print '* Listening on', PORT try: eventlet.serve(server, test_server) except Exception, msg: if DEBUG: print Exception, msg raise
def main(): """ Spawns the listener """ try: eventlet.serve(eventlet.listen((HOST, PORT)), handle, concurrency=CONCURRENCY) except socket.error as e: log.warn(e) eventlet.StopServe() sys.exit(0)
def run(self): """ Start the mgmt. server """ try: os.remove(self.__uds_file) except OSError: if os.path.exists(self.__uds_file): raise try: self.__socket.bind(self.__uds_file) except Exception as ex: # pylint: disable=broad-except raise RuntimeError('Unable to bind to mgmt socket %s: %s' % (self.__uds_file, ex)) self.__socket.listen(self.__concurrency) eventlet.serve(self.__socket, self.__handle_msg, concurrency=self.__concurrency)
def run(self): """ Start the mgmt server """ try: os.remove(self.__uds_file) except OSError: if os.path.exists(self.__uds_file): raise try: self.__socket.bind(self.__uds_file) except Exception as ex: # pylint: disable=broad-except raise RuntimeError('Unable to bind to mgmt socket %s: %s' % (self.__uds_file, ex)) self.__socket.listen(5) eventlet.serve(self.__socket, self.__handle_msg, concurrency=self.__concurrency)
def main(): logger.info("Starting orbited_node") parser = argparse.ArgumentParser( description='HammerD Server' ) parser.add_argument("--ip", default="127.0.0.1") parser.add_argument("--pubport", default="7777") parser.add_argument("--ctlport", default="7778") parser.add_argument("--tcpport", default="9999") arguments = parser.parse_args() control.bind("tcp://%s:%s" % (arguments.ip, arguments.ctlport)) publisher.bind("tcp://%s:%s" % (arguments.ip, arguments.pubport)) eventlet.spawn_n(zcommand_handler) eventlet.serve( eventlet.listen((arguments.ip, int(arguments.tcpport))), handler_ )
def serve_forever(self): eventlet.serve(eventlet.listen((self.ip, self.port)), self.handle)
def start(self): log.debug('Starting server') eventlet.serve(self.server, self.handle_connection)
def serve(sock, device_id, model): eventlet.serve(sock, functools.partial(start_remote, device_id, model))
def _run(self, application, socket): """Runs a server on the supplied socket in a new green thread.""" LOG.info(_('(%(pid)s) Server starting up on %(host)s:%(port)s') % {'pid': self._pid, 'host': self._host, 'port': self._port}) eventlet.serve(socket, application, concurrency=CONF.server_threads)
__author__ = 'yokoi-h' import eventlet def echo_handler(sock, addr): fd = sock.makefile() while True: print "before readline" line = fd.readline() print "after readline" print line if not line: break fd.write(line) fd.flush() if __name__ == '__main__': server_sock = eventlet.listen(('localhost', 3001)) eventlet.serve(server_sock, echo_handler)
import eventlet def myhandle(client_sock, client_addr): print("client connected", client_addr) eventlet.serve(eventlet.listen(('127.0.0.1', 9999)), myhandle)
def run(self): self.server = eventlet.listen((self.bind, self.port)) eventlet.serve(self.server, self.handle)
PORT = 3001 fds = [] def chat_handler(sock, addr): print('Participant joined chat') fd = sock.makefile() fds.append(fd) _loop_handler(fd) fds.remove(fd) print('Participant left chat') def _loop_handler(fd): while True: line = fd.readline() print('Chat: %s' % (line.strip(),)) if not line: break _broadcast_message(fd, line) def _broadcast_message(pfd, msg): for fd in fds: if fd is pfd: continue fd.write(msg) fd.flush() if __name__ == '__main__': print('Server starting up on port %d' % PORT) lister = eventlet.listen(('localhost', 3001)) eventlet.serve(lister, chat_handler)
def serve(self, callback): self.socket = eventlet.listen(('', 0)) self._local_host, self._local_port = self.socket.getsockname() self._local_ready.send(True) eventlet.serve(self.socket, callback)
def serve_store(sock, store, server=None): if isinstance(sock, tuple): sock = eventlet.listen(sock) if not server: server = MemcacheServer(store) eventlet.serve(sock, server)
except socket.error, e: if e.errno == 98: logging.critical("Cannot listen on (%s, %s): already in use" % (address, family)) raise elif e.errno == 13 and address[1] <= 1024: logging.critical("Cannot listen on (%s, %s) (you might need to launch as root)" % (address, family)) return logging.critical("Cannot listen on (%s, %s): %s" % (address, family, e)) return # Sleep to ensure we've dropped privileges by the time we start serving eventlet.sleep(0.5) # Start serving logging.info("Listening for requests on %s" % (address, )) eventlet.serve( sock, lambda sock, addr: self.handle(sock, addr, internal), concurrency = 10000, ) def resolve_host(self, host, protocol="http"): # Special case for empty hosts dict if not self.hosts: return NoHosts(self, host, "unknown") # Check for an exact or any subdomain matches bits = host.split(".") for i in range(len(bits)): for prefix in ["%s://" % protocol, ""]: subhost = prefix + (".".join(bits[i:])) if subhost in self.hosts: action, kwargs, allow_subs = self.hosts[subhost] if allow_subs or i == 0:
def serve_forever(self): eventlet.serve( eventlet.listen((self.ip, self.port)), self.handle )
sock_write(client_conn_fd, "LOCKED %s\r\n" %(key)) return LOCKED elif client_msg.startswith('UNLOCK'): key = client_msg.split()[1] if daemon_state == LOCKED: key_locked_status[key] = False sock_write(client_conn_fd, "UNLOCKED %s\r\n" %(key)) return UNLOCKED elif daemon_state == UNLOCKED: sock_write(client_conn_fd, LOCK_NEVER_ACQUIRED) return UNLOCKED elif client_msg.startswith('QUIT'): if daemon_state == LOCKED: sock_write(client_conn_fd, LOCK_NOT_RELEASED) return LOCKED elif daemon_state == UNLOCKED: sock_write(client_conn_fd, QUIT) return DONE def conn_handler(sock, addr): """Handles connections made by requesting clients""" sockfd = sock.makefile('rw') state = UNLOCKED while True: line = sockfd.readline().rstrip() state = handle_state(sockfd, line, state) if state == DONE: break eventlet.serve(eventlet.listen((HOST, PORT)), conn_handler)
def runNonBlockingSocket(self): listener = eventlet.listen( (self.host, self.PORT) ) print 'Recieving on %s, %s'%(self.host, self.PORT) eventlet.serve(listener, self.recieveData)
#coding=utf8 import eventlet import time def fetch(sock, addr): print addr pool = eventlet.GreenPool() eventlet.serve(eventlet.listen(("127.0.0.1", 9999)), fetch)
def chat_handler(sock, addr): print('Participant joined chat') fd = sock.makefile() fds.append(fd) _loop_handler(fd) fds.remove(fd) print('Participant left chat') def _loop_handler(fd): while True: line = fd.readline() print('Chat: %s' % (line.strip(), )) if not line: break _broadcast_message(fd, line) def _broadcast_message(pfd, msg): for fd in fds: if fd is pfd: continue fd.write(msg) fd.flush() if __name__ == '__main__': print('Server starting up on port %d' % PORT) lister = eventlet.listen(('localhost', 3001)) eventlet.serve(lister, chat_handler)
elif e.errno == errno.EACCES and address[1] <= 1024: logging.critical( "Cannot listen on (%s, %s) (you might need to launch as root)" % (address, family)) return logging.critical("Cannot listen on (%s, %s): %s" % (address, family, e)) return # Sleep to ensure we've dropped privileges by the time we start serving eventlet.sleep(0.5) # Start serving logging.info("Listening for requests on %s" % (address, )) try: eventlet.serve( sock, lambda sock, addr: self.handle(sock, addr, internal), concurrency=10000, ) finally: sock.close() def resolve_host(self, host, protocol="http"): # Special case for empty hosts dict if not self.hosts: return NoHosts(self, host, "unknown") # Check for an exact or any subdomain matches bits = host.split(".") for i in range(len(bits)): for prefix in ["%s://" % protocol, ""]: subhost = prefix + (".".join(bits[i:])) if subhost in self.hosts:
def serve(sock, handler): try: return eventlet.serve(sock, handler) except socket.error: pass