def __init__(self, *args, **opts): super(Telnet, self).__init__() self.args = args self.opts = opts if len(args) == 1: if os.path.exists(args[0]): UNIXClient(channel=self.channel).register(self) host = dest = port = args[0] dest = (dest, ) else: raise OSError("Path %s not found" % args[0]) else: if not opts["udp"]: TCPClient(channel=self.channel).register(self) else: UDPClient(0, channel=self.channel).register(self) host, port = args port = int(port) dest = host, port self.host = host self.port = port print("Trying %s ..." % host) if not opts["udp"]: self.fire(connect(*dest, secure=opts["secure"])) else: self.fire(write((host, port), b"\x00"))
def test_unix(tmpfile, Poller): m = Manager() + Poller() server = Server() + UNIXServer(tmpfile) client = Client() + UNIXClient() server.register(m) client.register(m) m.start() try: assert pytest.wait_for(server, "ready") assert pytest.wait_for(client, "ready") client.fire(connect(tmpfile)) assert pytest.wait_for(client, "connected") assert pytest.wait_for(server, "connected") assert pytest.wait_for(client, "data", b"Ready") client.fire(write(b"foo")) assert pytest.wait_for(server, "data", b"foo") client.fire(close()) assert pytest.wait_for(client, "disconnected") assert pytest.wait_for(server, "disconnected") server.fire(close()) assert pytest.wait_for(server, "closed") finally: m.stop()
def test_unix(tmpdir, Poller): m = Manager() + Poller() sockpath = tmpdir.ensure("test.sock") filename = str(sockpath) server = Server() + UNIXServer(filename) client = Client() + UNIXClient() server.register(m) client.register(m) m.start() try: assert pytest.wait_for(server, "ready") assert pytest.wait_for(client, "ready") client.fire(connect(filename)) assert pytest.wait_for(client, "connected") assert pytest.wait_for(server, "connected") assert pytest.wait_for(client, "data", b"Ready") client.fire(write(b"foo")) assert pytest.wait_for(server, "data", b"foo") client.fire(close()) assert pytest.wait_for(client, "disconnected") assert pytest.wait_for(server, "disconnected") server.fire(close()) assert pytest.wait_for(server, "closed") finally: m.stop() os.remove(filename)
def init(self, sock, agent_socket, channel): """ Args: sock - related client socket agent_socket - path to agent UNIX socket channel - unique client ID """ self.agent_socket = agent_socket self.sock = sock print("Initialized a client with channel", channel) print("Opening unix client to socket {}".format(agent_socket)) UNIXClient(channel=channel).register(self)