这听起来像是Pyro4 包的工作。这是一个基于他们的“简单示例”的示例,并带有一些额外的代码来自动启动名称服务器并通过网络进行监听。
首先在每台机器上使用以下命令来安装Pyro4:
pip install pyro4
在服务器上,将该脚本另存为server.py,然后通过python server.py以下命令在终端窗口中运行:
# saved as server.py
import Pyro4, Pyro4.naming
import socket, threading
# Define an object that will be accessible over the network.
# This is where all your code should go...
@Pyro4.expose
class MessageServer(object):
def show_message(self, msg):
print("Message received: {}".format(msg))
# Start a Pyro nameserver and daemon (server process) that are accessible
# over the network. This has security risks; see
# https://pyro4.readthedocs.io/en/stable/security.html
hostname = socket.gethostname()
ns_thread = threading.Thread(
target=Pyro4.naming.startNSloop, kwargs={&#