Exemple #1
0
def main():
    import warnings
    warnings.simplefilter("ignore", DeprecationWarning)

    try:
        port = int(sys.argv[1])
    except:
        port = DEFAULT_SERVER_PORT

    conn = None
    if port > 19000:
        # Named server
        try:
            __import__("win32file")
            np_server = NamedPipeStream.create_server(str(port))
            conn = connect_stream(np_server, ModSlaveService)
            try:
                conn.serve_all()
            except Exception:
                pass
            finally:
                if (conn is not None) and not conn.closed:
                    conn.close()
                exit()
        except SystemExit:
            raise
        except:
            conn = None

    if conn is None:
        t = SimpleServer(ModSlaveService, port=port, auto_register=False)
        t.start()
def main():
    """
    Initialize rpyc connection.
    """
    # Don't compress to improve speed.
    rpyc.core.channel.Channel.COMPRESSION_LEVEL = 0

    # Importing idc here so we can still import the server externally.
    import idc

    if not idc.ARGV[1:]:
        raise RuntimeError(f"No connection parameter provided.")

    if sys.platform == "win32":
        pipe_name = idc.ARGV[1]
        stream = NamedPipeStream.create_server(pipe_name)
        with rpyc.classic.connect_stream(stream) as srv:
            srv.serve_all()
    else:
        socket_path = idc.ARGV[1]
        server = OneShotServer(SlaveService,
                               socket_path=socket_path,
                               auto_register=False)
        server.start()

    idc.qexit(0)
    def win_connect(pipe_name, retry=10) -> rpyc.Connection:
        """
        Connects to bridge using Windows named pipe.
        """
        pipe_name = NamedPipeStream.NAMED_PIPE_PREFIX + pipe_name
        import pywintypes
        for i in range(retry):
            try:
                logger.debug(f"Connecting to pipe: {pipe_name}, try {i + 1}")
                stream = NamedPipeStream.create_client(pipe_name)
                link = rpyc.classic.connect_stream(stream)
                link.ping()
                logger.debug(f"Connected to {pipe_name}")
                return link
            except pywintypes.error:
                time.sleep(1)
                continue

        raise DragodisError(f"Could not connect to {pipe_name} after {retry} tries.")
Exemple #4
0
 def pipe_server(self):
     self.np_server = NamedPipeStream.create_server("floop")
     self.server = rpyc.connect_stream(self.np_server)
     self.server.serve_all()
Exemple #5
0
 def setUp(self):
     self.pipe_server_thread = rpyc.spawn(self.pipe_server)
     time.sleep(1) # make sure server is accepting already
     self.np_client = NamedPipeStream.create_client("floop")
     self.client = rpyc.connect_stream(self.np_client)
Exemple #6
0
 def setup(self):
     self.pipe_server_thread = Thread(target=self.pipe_server)
     self.pipe_server_thread.start()
     time.sleep(1) # make sure server is accepting already
     self.np_client = NamedPipeStream.create_client("floop")
     self.client = rpyc.connect_stream(self.np_client)
 def pipe_server(self):
     self.np_server = NamedPipeStream.create_server("floop")
     self.server = rpyc.connect_stream(self.np_server)
     self.server.serve_all()
 def setUp(self):
     self.pipe_server_thread = Thread(target=self.pipe_server)
     self.pipe_server_thread.start()
     time.sleep(1)  # make sure server is accepting already
     self.np_client = NamedPipeStream.create_client("floop")
     self.client = rpyc.connect_stream(self.np_client)