我有两台不同的电脑。我想让其中一个成为主机,另一个成为发送信息的代理。我想用osbrain做这个。然而,我面临一个问题
Host Agent正在打开服务器。2.我的代理连接到服务器,但无法在两者之间通信。你能帮我吗
Host_Agent.py
from osbrain import run_nameserver
from osbrain.proxy import locate_ns
from osbrain import run_agent
import osbrain
import time
import pickle
def log_message(agent, message):
agent.log_info('Received: %s' % message)
if __name__ == '__main__':
ns_sock = '127.0.0.1:1212'
osbrain.config['TRANSPORT'] = 'tcp'
ns_proxy = run_nameserver(ns_sock)
ns_addr = locate_ns(ns_sock)
# New Agent
while True:
time.sleep(5)
agents_in_NS = osbrain.nameserver.NameServer.agents(ns_proxy)
print('Current agents in Nameserver are: %s' %agents_in_NS)
新_Agent.py
from osbrain import NSProxy
from osbrain import run_agent
import osbrain
import Pyro4
import pickle
import time
if __name__ == '__main__':
ns_addr = '127.0.0.1:1212'
osbrain.config['TRANSPORT'] = 'tcp'
ns_proxy = NSProxy(ns_addr)
print('Registering Agent with server...')
agent_proxy = run_agent('Agent3', ns_addr)
address = agent_proxy.bind('PUSH', alias='main')
time.sleep(5)
print('I have joined the nameserver!')
for i in range(1000):
print("I try to say HEY!")
agent_proxy.send('main',message='Hey')
print("I tried")
time.sleep(2)
print("Done")
127.0.0.1
是环回地址,因此无论您在何处使用它,服务器都只会侦听来自它所运行的机器的连接在
Host_Agent.py
中,将本地主机地址(ns_sock = '127.0.0.1:1212'
)更改为whildcard(ns_sock = '0.0.0.0:1212'
)。这将允许服务器侦听来自所有主机的所有入站连接现在,在
New_Agent.py
中,将localhost替换为运行Host_Agent.py
的机器的IP地址相关问题 更多 >
编程相关推荐