Enter code import rpyc
class ClientOpsService(rpyc.Service): def on_connect(self, conn): # code that runs when a connection is created # (to init the service, if needed) pass
def on_disconnect(self, conn): # code that runs after the connection has already closed # (to finalize the service, if needed) pass
def exposed_ops_ping(self): # this is an exposed method return "ops-pong"
c = rpyc.connect("localhost", 18861, service = ClientOpsService)
ret=c.root.get_answer()print(f"ret={ret}")here...
Enter code herimport rpycimport sys
class ServerService(rpyc.Service):
def exposed_get_answer(self): # this is an exposed method print(f"{sys._getframe( ).f_code.co_name} called") r = self._conn.root.ops_ping() print(r) return 42
if __name__ == "__main__": client_service=None client_func=None from rpyc.utils.server import ThreadedServer
t = ThreadedServer(ServerService(), port=18861) t.start()e...
Enter code heredan@dan-om-linux:~/work/om_v1.0/src/control/sample_rpyc$ python my_client.py Traceback (most recent call last):
File "my_client.py", line 25, in <module>
ret=c.root.get_answer()
File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/netref.py", line 199, in __call__
return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/netref.py", line 75, in syncreq
return conn.sync_request(handler, proxy, *args)
File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/protocol.py", line 471, in sync_request
return self.async_request(handler, *args, timeout=timeout).value
File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/async_.py", line 97, in value
raise self._obj
AttributeError: 'ServerService' object has no attribute '_conn'
========= Remote Traceback (1) =========
Traceback (most recent call last):
File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/protocol.py", line 329, in _dispatch_request
res = self._HANDLERS[handler](self, *args)
File "/home/dan/.local/lib/python3.6/site-packages/rpyc/core/protocol.py", line 590, in _handle_call
return obj(*args, **dict(kwargs))
File "my_service.py", line 9, in exposed_get_answer
r = self._conn.root.ops_ping()
AttributeError: 'ServerService' object has no attribute '_conn'
...