def client(addr): sock = socket.socket() sock.connect(addr) stream = raw.Stream(sock.makefile('rb', -1), sock.makefile('wb', 0)) requester = Requester(lambda chunk: stream.write_chunk(json.dumps(chunk))) dispatcher = Dispatcher(None, requester.handle_response) conn = PyConnector(requester) gevent.spawn(util.dispatch_loop, stream, dispatcher, json) return conn
def client(addr): sock = socket.socket() sock.connect(addr) stream = raw.Stream(sock.makefile('rb+')) requester = Requester(lambda chunk: stream.write_chunk(json.dumps(chunk))) dispatcher = Dispatcher(None, requester.handle_response) conn = PyConnector(requester) t = threading.Thread(target=util.dispatch_loop, args=(stream, dispatcher, json)) t.daemon = True t.start() return conn
def __init__(self, config): address = config['control']['socket'] if address[:1] == '@': address = '\x00' + address[1:] self._sock = sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect(address) stream = framing.Stream(sock.makefile('rb', -1), sock.makefile('rw', 0)) self._requester = requester = jsonrpc.Requester( lambda chunk: stream.write_chunk(json.dumps(chunk))) super(ControlConnector, self).__init__(requester) self._dispatcher = dispatcher = jsonrpc.Dispatcher( None, requester.handle_response) self._task = gevent.spawn(dispatch_loop, stream, dispatcher)
def _handle_request(sock, handler): rfile = sock.makefile('rb', -1) wfile = sock.makefile('wb', 0) stream = framing.Stream(rfile, wfile) dispatcher = jsonrpc.Dispatcher(handler) dispatch_loop(stream, dispatcher)