我想从服务器到客户端和客户端到服务器连续发送数据,但不幸的是我没有得到所需的输出。谁能指出我做错了什么?
服务器端:
import rpyc
import threading
class MyService(rpyc.Service):
def on_connect(self, conn):
print("connected to", conn.root.get_service_name())
self.exposed(conn)
def on_disconnect(self, conn):
pass
def func1(self):
#return "hello world"
inp = input("")
return inp
def exposed(self, conn):
while True:
a = conn.root.func2()
print(a)
if __name__ == "__main__":
from rpyc.utils.server import ThreadedServer
print("Server is ready")
t = ThreadedServer(MyService, port=8008, protocol_config={'allow_all_attrs': True}).start()
#
客户端
import rpyc
import time
class ClientService(rpyc.SlaveService):
def func2(self):
#return "Hello World"
inp = input("")
return inp
if __name__ == "__main__":
print("waiting for connection")
conn = rpyc.connect("192.168.10.142", 8008, service=ClientService)
print("connected to", conn.root.get_service_name())
while True:
a=conn.root.func1()
print(a)