i can't create Distributed system on osbrain

I have 2 different computers. I want to make one of them a host and the other an agent sending information. I want to do this with osbrain. However, I am facing a problem.

Host Agent is opening the server. 2. My agent connects to the server, but I cannot communicate between the two. Can you help me?

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)

New_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")

Upvotes: 0

Views: 213

Answers (1)

prithajnath
prithajnath

Reputation: 2115

127.0.0.1 is the loopback address so anywhere you us it the server will only listen for connections from only the machine it's running on

In Host_Agent.py, change the localhost address(ns_sock = '127.0.0.1:1212') to a whildcard (ns_sock = '0.0.0.0:1212'). This will let your server listen for all inbound connections from all hosts.

Now, in New_Agent.py, replace localhost with the IP address of the machine that Host_Agent.py is running on

ns_addr = '${IP_ADDRESS_OF_OTHER_MACHINE}:1212'

Upvotes: 2

Related Questions