Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python rpyc服务器调用客户端方法_Python_Try Catch_Rpyc - Fatal编程技术网

Python rpyc服务器调用客户端方法

Python rpyc服务器调用客户端方法,python,try-catch,rpyc,Python,Try Catch,Rpyc,我目前正在使用rpyc构建一个服务器和多个将连接到它的客户端。我希望将客户机中的数据推送到服务器进行进一步处理,我希望服务器在客户机连接到服务器时调用客户机方法。从他们的教程中,它说客户端可以向服务器公开他们的服务,但我得到了错误 我的服务器的代码: import rpyc class TestService(rpyc.Service): def on_connect(self, conn): conn.root.example() if __name__ == "_

我目前正在使用rpyc构建一个服务器和多个将连接到它的客户端。我希望将客户机中的数据推送到服务器进行进一步处理,我希望服务器在客户机连接到服务器时调用客户机方法。从他们的教程中,它说客户端可以向服务器公开他们的服务,但我得到了错误

我的服务器的代码:

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()
我的客户代码:

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"
客户端可以连接到服务器,但线程中会出现异常和错误:raise EOFError(“流已关闭”)。它在抱怨conn.root.example()行,我不知道正确的语法是什么,教程也没有指定

任何帮助都将不胜感激