1

I am currently using rpyc for constructing a server and multiple clients that will connect to it. I have data in the clients that I would like to push to the server for further processing, and I would like to do it with the server calling a client method whenever the client connects to the server. From their tutorial, it says that clients can expose their service to the server, but I am getting errors.

Code for my server:

import rpyc

class TestService(rpyc.Service):
    def on_connect(self, conn):
        conn.root.example()

if __name__ == "__main__":
    from rpyc.utils.server import ThreadedServer
    t = ThreadedServer(TestService, port=18861, auto_register=True)
    t.start()

Code for my client:

import rpyc

class ClientService(rpyc.Service):
    def exposed_example(self):
        print "example"

if __name__ == "__main__":
    try:
        rpyc.discover("test")
        c = rpyc.connect_by_service("test", service=ClientService)
        c.close()
    except:
        print "could not find server"

The client is able to connect to the server, but there will be an exception in thread and an error: raise EOFError("stream has been closed"). It is complaining about the line conn.root.example() and I don't know what the correct syntax would be, and the tutorial did not specify at all.

Any help will be much appreciated!

Rick Chow
  • 11
  • 3

1 Answers1

0

I Just had the same problem, and the answer is that in your TestService you do the conn.root.example() call, you are not really connected to the other side.

You should do something like

class TestService(rpyc.Service):
def on_connect(self, conn):
    res = super().on_connect(conn)
    conn.root.example()

    return res
CBrunain
  • 377
  • 4
  • 12