def spawn_handler(): gsvar = os.environ.get('GRAPHSERVER') if not gsvar: return spawn_local_handler() else: try: host, port = gsvar.split(':') host = host or '127.0.0.1' port = int(port) except ValueError: raise ValueError("$GRAPHSERVER must be set to HOST:PORT, got %r" % (gvvar, )) import socket s = socket.socket() s.connect((host, port)) return msgstruct.SocketIO(s)
def listen_server(local_address): import socket, graphclient, thread if isinstance(local_address, str): if ':' in local_address: interface, port = local_address.split(':') else: interface, port = '', local_address local_address = interface, int(port) s1 = socket.socket() s1.bind(local_address) s1.listen(5) print 'listening on %r...' % (s1.getsockname(), ) while True: conn, addr = s1.accept() print 'accepted connexion from %r' % (addr, ) sock_io = msgstruct.SocketIO(conn) handler_io = graphclient.spawn_local_handler() thread.start_new_thread(copy_all, (sock_io, handler_io)) thread.start_new_thread(copy_all, (handler_io, sock_io)) del sock_io, handler_io, conn
def spawn_graphserver_handler(address): import socket s = socket.socket() s.connect(address) return msgstruct.SocketIO(s)