我目前正在使用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"
客户端能够连接到服务器,但是线程中将出现异常和错误:引发EOFError(“流已关闭”)。它在抱怨conn.root.example()行,我不知道正确的语法是什么,并且本教程根本没有指定。
任何帮助将不胜感激!