Skip to content

Error with OSBrain Communication Across Separate Machines? #341

@sjanko2

Description

@sjanko2

Hello,

Thank you for your development on this wonderful library. I have been using it for the last few years in work towards my PhD and very much appreciate the work you all do!

I have been running simulations with multiple agents connected to a local host server on one computer for a while now. This works successfully. Now, my coworker and I are attempting to put the scripts on separate computers and have them communicate through direct ethernet connection via the OSBrain library and are having difficulty. We have one computer hosting the nameserver ("Host_Computer", a Linux OS) and the other computer attempting to register with it ("Agent_Computer", a Windows OS). We get an error that indicates the following on the Agent_Computer:

OSError: [WinError 10049] The requested address is not valid in its context

and

Pyro4.errors.CommunicationError: cannot connect to ('0.0.0.0', 5020): [WinError 10049] The requested address is not valid in its context

I have included the scripts I made to illustrate the problem, and attached a screenshot of the full stacktrace on the Agent_Computer (see first screenshot). The Host_Computer runs perfectly and simply "waits" for the Nameserver to be populated with the Agent_Computer (see second screenshot).

I'd just like to note that this code works perfectly fine if run on the same computer (such as with the Multirun plug-in in Pycharm). The Agent_Computer connects to the Host_Computer and all is well. We have only run into this issue when trying to connect on multiple machines.

Any advice you can provide would be great, thanks so much!

Sam


Host_Computer.py


from osbrain import run_nameserver
from osbrain.proxy import locate_ns
import osbrain
import time

def main():
    # Windows
    # ns_sock = '127.0.0.1:1125'

    # # Linux
    ns_sock = '0.0.0.0:5020'

    osbrain.config['TRANSPORT'] = 'tcp'

    ns_proxy = run_nameserver(ns_sock)
    ns_addr = locate_ns(ns_sock)

    agents_in_NS = osbrain.nameserver.NameServer.agents(ns_proxy)

    while(len(agents_in_NS)<1):
        agents_in_NS = osbrain.nameserver.NameServer.agents(ns_proxy)
        print('Current agents in Nameserver are: %s' %agents_in_NS)
        time.sleep(1)

    print('All agents have joined!')

if __name__ == '__main__':

    main()

Agent_Computer.py


from osbrain import NSProxy
from osbrain import run_agent
import osbrain
import Pyro4

def main():
    ns_addr = '192.168.0.42:5020'

    osbrain.config['TRANSPORT'] = 'tcp'

    # Look for nameserver, if can't find then try again
    while True:
        try:
            ns_proxy = NSProxy(ns_addr)

            break

        except Pyro4.errors.CommunicationError:
            print('Pyro4.errors.CommunicationError, no nameserver found')
            print('Trying again...')

            pass

        except TimeoutError:
            print('TimeoutError, no nameserver found')
            print('Trying again...')

            pass
    
    # Join nameserver, if can't find then try again
    while True:
        try:
            # Activate and register with server
            print('Registering Agent with server...')
            agent_proxy = run_agent('Agent1', ns_addr)

            # Wait for proxy to set up
            checkstatus = agent_proxy.get_attr('_running')

            while checkstatus == False:
                checkstatus = agent_proxy.get_attr('_running')

            # Verify that agent has registered successfully
            agents_in_NS = osbrain.nameserver.NameServer.agents(ns_proxy)
            print('The following agents are in the server: %s' % agents_in_NS)

            break

        except KeyError:
            print('Key Error')
            print('Trying again...')

            pass

        except Pyro4.errors.CommunicationError:
            print('Pyro4.errors.CommunicationError, no nameserver found')
            print('Trying again...')

            pass

        except TimeoutError:
            print('TimeoutError, no nameserver found')
            print('Trying again...')

            pass

    print('I have joined the nameserver!')

if __name__ == '__main__':

    main()

Screenshot 1

Screenshot 2

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions