gpt4 book ai didi

python rpyc "socket.error: [Errno 113] No route to host"

转载 作者:太空宇宙 更新时间:2023-11-04 03:49:24 25 4
gpt4 key购买 nike

我有两台使用python rpyc 的机器,一台是server(ip:10.0.3.120),另一台是client(ip:10.0.3.197)。代码如下:

服务器 (ip:10.0.3.120)

from rpyc import Service
from rpyc.utils.server import ThreadedServer

class TestService(Service):

def exposed_test(self, num):
return num + 1

sr = ThreadedServer(TestService, port=9999, auto_register=False)
sr.start()

客户端 (ip:10.0.3.129)

import rpyc
conn = rpyc.connect('10.0.3.120', 9999)
cResult = conn.root.test(11)
conn.close()

print cResult

当我运行 serverclient 时客户端显示此错误:

Traceback (most recent call last):
File "rpyc_client.py", line 4, in <module>
conn = rpyc.connect('10.0.3.120', 9999)
File "/usr/local/lib/python2.7/site-packages/rpyc-3.2.3-py2.7.egg/rpyc/utils/factory.py", line 89, in connect
s = SocketStream.connect(host, port, ipv6 = ipv6)
File "/usr/local/lib/python2.7/site-packages/rpyc-3.2.3-py2.7.egg/rpyc/core/stream.py", line 114, in connect
return cls(cls._connect(host, port, **kwargs))
File "/usr/local/lib/python2.7/site-packages/rpyc-3.2.3-py2.7.egg/rpyc/core/stream.py", line 92, in _connect
s.connect((host, port))
File "/usr/local/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)

connect 方法如何使用?如果我用公网IP搭建一个rpyc服务器,可以在家里连接吗??非常感谢!

最佳答案

首先,检查连接命令 ping。在您的代码服务器中运行在本地主机。为了使它可以从您的正确地址或 * 之外访问(然后服务器将在当前机器的所有可能地址上运行)。我认为 auto_register 必须等于 None。

from rpyc import Service
from rpyc.utils.server import ThreadedServer

class TestService(Service):

def exposed_test(self, num):
return num + 1

sr = ThreadedServer(TestService, hostname='10.0.3.120', port=9999, auto_register=None)
# or sr = ThreadedServer(TestService, hostname='*', port=9999, auto_register=None)
sr.start()

关于 python rpyc "socket.error: [Errno 113] No route to host",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22032635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com