def listen(self, host, port): factory = self.loop.create_server(self, host, port) self.server = self.loop.run_until_complete(factory) Trace.info("listening on {}:{}", host, port) self.thread.start()
def connect(self, host, port): self.remote_host = host self.remote_port = port Trace.info("connecting to {}:{}", host, port) factory = self.loop.create_connection(self, host, port) transport, protocol = self.loop.run_until_complete(factory) self.thread.start()
def _on_connect(self, result, context): super(TcpClient, self)._on_connect(result, context) if result: peername = context.transport.get_extra_info('peername') Trace.info("connected to {}:{}", peername[0], peername[1]) else: Trace.error("error connecting to {}:{}", self.remote_host, self.remote_port)
def startup(): """Starts all the flows attached to the hub.""" Trace.debug("starting up") Hub.instance.setup() Hub.instance.start_flows() TimeFlow.get().reserve_repetition(Hub.heartbeat_event, \ timedelta(seconds=Config.heartbeat_interval)) Trace.info("started")
def listen(self, host, port): self.dispatcher.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.dispatcher.bind((host, port)) self.dispatcher.listen(5) Trace.info("listening on {}:{}", host, port) self.thread.start()
def _on_connect(self, result, context): super(TcpClient, self)._on_connect(result, context) if result: peername = context.socket.getpeername() Trace.info("connected to {}:{}", peername[0], peername[1]) context.peername = peername else: Trace.error("error connecting to {}:{}", self.remote_host, self.remote_port)
def connect(self, host, port): self.connecting = True self.remote_host = host self.remote_port = port Trace.info("connecting to {}:{}", host, port) self.dispatcher.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.dispatcher.connect((host, port)) self.thread.start()
def on_disconnect(self, handle, context): Trace.info("{} disconnected {} {}", self.name, handle, context) self._on_disconnect(handle, context) if handle != 0: SessionBasedLink.handle_pool.release(handle) LinkSessionDisconnected().setattrs(link_name=self.name, handle=handle, context=context).post()
def on_connect(self, result, context): Trace.info("{} connected {} {}", self.name, result, context) if result: handle = SessionBasedLink.handle_pool.acquire() context.handle = handle self._on_connect(result, context) LinkSessionConnected().setattrs(link_name=self.name, result=result, context=context).post()
def _on_disconnect(self, handle, context): super(TcpServer, self)._on_disconnect(handle, context) peername = context.transport.get_extra_info('peername') Trace.info("disconnected from {}:{}", peername[0], peername[1])
def _on_connect(self, result, context): super(TcpServer, self)._on_connect(result, context) if result: peername = context.transport.get_extra_info('peername') Trace.info("accepted from {}:{}", peername[0], peername[1])
def shutdown(): """Stops all the flows attached to the hub.""" Trace.debug("shutting down") Hub.instance.stop_flows() Hub.instance.teardown() Trace.info("stopped")
def _on_disconnect(self, handle, context): super(TcpServer, self)._on_disconnect(handle, context) peername = context.peername Trace.info("disconnected from {}:{}", peername[0], peername[1])
def _on_connect(self, result, context): super(TcpServer, self)._on_connect(result, context) if result: peername = context.socket.getpeername() Trace.info("accepted from {}:{}", peername[0], peername[1]) context.peername = peername