Esempio n. 1
0
def test_server_send_multicast(app, watcher, manager):
    client1 = App().register(manager)
    node1 = Node().register(client1)
    chan1 = node1.add('client1', *app.bind)
    assert watcher.wait('connected', channel=chan1)
    watcher.clear()

    client2 = App().register(manager)
    node2 = Node().register(client2)
    chan2 = node2.add('client2', *app.bind)
    assert watcher.wait('connected', channel=chan2)
    watcher.clear()

    client3 = App().register(manager)
    node3 = Node().register(client3)
    chan3 = node3.add('client3', *app.bind)
    assert watcher.wait('connected', channel=chan3)
    watcher.clear()

    event = return_value()
    app.server.send_to(event, app.server.get_socks())
    assert watcher.wait('return_value')

    for _ in range(3):
        if watcher.count("return_value") == 3:
            break
        sleep(1)
    assert watcher.count("return_value") == 3

    client1.unregister()
    client2.unregister()
    client3.unregister()
Esempio n. 2
0
def test_server_send_multicast(app, watcher, manager):
    client1 = App().register(manager)
    node1 = Node().register(client1)
    chan1 = node1.add('client1', *app.bind)
    assert watcher.wait('connected', channel=chan1)


    client2 = App().register(manager)
    node2 = Node().register(client2)
    chan2 = node2.add('client2', *app.bind)
    assert watcher.wait('connected', channel=chan2)

    client3 = App().register(manager)
    node3 = Node().register(client3)
    chan3 = node3.add('client3', *app.bind)
    assert watcher.wait('connected', channel=chan3)

    event = return_value()
    app.server.send_to(event, app.server.get_socks()[:2])
    assert watcher.wait('return_value')

    event_cnt = 0
    with watcher._lock:
        for event in watcher.events:
            if event.name == 'return_value':
                event_cnt += 1

    assert event_cnt == 2

    client1.unregister()
    client2.unregister()
    client3.unregister()
Esempio n. 3
0
def test_server_send_multicast(app, watcher, manager):
    client1 = App().register(manager)
    node1 = Node().register(client1)
    chan1 = node1.add('client1', *app.bind)
    assert watcher.wait('connected', channel=chan1)

    client2 = App().register(manager)
    node2 = Node().register(client2)
    chan2 = node2.add('client2', *app.bind)
    assert watcher.wait('connected', channel=chan2)

    client3 = App().register(manager)
    node3 = Node().register(client3)
    chan3 = node3.add('client3', *app.bind)
    assert watcher.wait('connected', channel=chan3)

    event = return_value()
    app.server.send_to(event, app.server.get_socks()[:2])
    assert watcher.wait('return_value')

    event_cnt = 0
    with watcher._lock:
        for event in watcher.events:
            if event.name == 'return_value':
                event_cnt += 1

    assert event_cnt == 2

    client1.unregister()
    client2.unregister()
    client3.unregister()
Esempio n. 4
0
class Client(Network_Node, circuits.core.BaseComponent):
    def __init__(self, host="0.0.0.0", port=50552, socket=None):
        super().__init__()
        self.node = Node((self.host, self.port))
        self.node.register(self)
        self.socket = socket
        #This is the channel that the server's client is listening on.
        #The fact that I have to use this to talk exclusively to the server strongly
        #suggests that either circuits' API is all sorts of broken or I horribly misunderstand
        #it
        #This is GROOOOOSSSS
        self.server_channel = ""
        #Eventually, I'll need to grab player name somehow.
        self.player = Player()
    def connect(self, host="0.0.0.0", port=50551):
        self.node.add("server", host, port)
        self.server_channel = sha256("{0:s}:{1:d}".format(host, port).encode("utf-8")
                                    ).hexdigest()
    @circuits.handler("connected")
    def connected(self, host, port):
        #self.fire(remote(write(Join_Event(self.player).bytify()), "server"))
        self.fire(write(bytify(Join_Event(self.player))), self.server_channel)
    def go(self):
        self.gui = views.GUI()
        debug("Made gui")
        self.gui.first_view_class = views.Login_View
        self.start()
        debug("Srtarting gui")
        self.gui.run()
        debug("Started")

    def update(self):
        self.game.update()
Esempio n. 5
0
    def init(self, args, opts):
        if opts.debug:
            Debugger().register(self)

        if ":" in opts.bind:
            address, port = opts.bind.split(":")
            port = int(port)
        else:
            address, port = opts.bind, 8000

        node = Node().register(self)
        node.add('peer_name', address, port)
Esempio n. 6
0
    def init(self, args, opts):
        if opts.debug:
            Debugger().register(self)

        if ":" in opts.bind:
            address, port = opts.bind.split(":")
            port = int(port)
        else:
            address, port = opts.bind, 8000

        node = Node().register(self)
        node.add('peer_name', address, port)
Esempio n. 7
0
def test_auto_reconnect(app, watcher, manager):
    # add client
    client = App().register(manager)
    node = Node().register(client)
    chan = node.add('client1', *app.bind, reconnect_delay=1, connect_timeout=1)
    assert watcher.wait('connected', channel=chan)

    # close server
    app.fire(close(), app.channel)
    assert watcher.wait('closed', channel=app.channel)

    app.unregister()
    assert watcher.wait('unregistered', channel=app.channel)


    for i in range(5):
        watcher.clear()
        assert watcher.wait('connect', channel=chan)
        assert watcher.wait('unreachable', channel=chan)

    # open server
    app = Node(port=app.bind[1], server_ip=app.bind[0])
    app.register(manager)

    assert watcher.wait('registered', channel=app.channel)
    assert watcher.wait('connected_to', channel=app.channel)

    client.unregister()
    def init(self, args, opts):
        if opts.debug:
            Debugger().register(self)

        if ":" in opts.bind:
            address, port = opts.bind.split(":")
            port = int(port)
        else:
            address, port = opts.bind, 8000

        auto_remote_event = {
            'increment': '*'
        }

        node = Node().register(self)
        node.add('peer_name', address, port, auto_remote_event=auto_remote_event)
Esempio n. 9
0
def test_auto_reconnect(app, watcher, manager):
    # add client
    client = App().register(manager)
    node = Node().register(client)
    chan = node.add('client1', *app.bind, reconnect_delay=1, connect_timeout=1)
    assert watcher.wait('connected', channel=chan)
    watcher.clear()

    # close server
    app.fire(close(), app.channel)
    assert watcher.wait('closed', channel=app.channel)
    watcher.clear()

    # client gets an unreachable
    assert watcher.wait('connect', channel=chan)
    assert watcher.wait('unreachable', channel=chan)
    watcher.clear()

    # start a new server
    node2 = Node(port=app.bind[1], server_ip=app.bind[0])
    node2.register(manager)
    assert watcher.wait('ready', channel=node2.channel)
    watcher.clear()

    assert watcher.wait('connected', channel=chan)

    client.unregister()
Esempio n. 10
0
def test_auto_reconnect(app, watcher, manager):
    # add client
    client = App().register(manager)
    node = Node().register(client)
    chan = node.add('client1', *app.bind, reconnect_delay=1, connect_timeout=1)
    assert watcher.wait('connected', channel=chan)

    # close server
    app.fire(close(), app.channel)
    assert watcher.wait('closed', channel=app.channel)

    app.unregister()
    assert watcher.wait('unregistered', channel=app.channel)

    for _ in range(5):
        watcher.clear()
        assert watcher.wait('connect', channel=chan)
        assert watcher.wait('unreachable', channel=chan)

    # open server
    app = Node(port=app.bind[1], server_ip=app.bind[0])
    app.register(manager)

    assert watcher.wait('registered', channel=app.channel)
    assert watcher.wait('connected_to', channel=app.channel)

    client.unregister()
Esempio n. 11
0
def test_server_send_all(app, watcher, manager):
    client1 = App().register(manager)
    node1 = Node().register(client1)
    chan = node1.add('client1', *app.bind)
    assert watcher.wait('connected', channel=chan)

    client2 = App().register(manager)
    node2 = Node().register(client2)
    chan = node2.add('client2', *app.bind)
    assert watcher.wait('connected', channel=chan)

    event = return_value()
    app.server.send_all(event)
    assert watcher.wait('return_value')

    client1.unregister()
    client2.unregister()
Esempio n. 12
0
def test_server_send(app, watcher, manager):
    client1 = App().register(manager)
    node1 = Node().register(client1)
    chan1 = node1.add('client1', *app.bind)
    assert watcher.wait('connected', channel=chan1)

    client2 = App().register(manager)
    node2 = Node().register(client2)
    chan2 = node2.add('client2', *app.bind)
    assert watcher.wait('connected', channel=chan2)

    event = return_value()
    app.server.send(event, app.server.get_socks()[0], no_result=True)
    assert watcher.wait('return_value')

    client1.unregister()
    client2.unregister()
Esempio n. 13
0
def test_server_send_all(app, watcher, manager):
    client1 = App().register(manager)
    node1 = Node().register(client1)
    chan = node1.add('client1', *app.bind)
    assert watcher.wait('connected', channel=chan)

    client2 = App().register(manager)
    node2 = Node().register(client2)
    chan = node2.add('client2', *app.bind)
    assert watcher.wait('connected', channel=chan)

    event = return_value()
    app.server.send_all(event)
    assert watcher.wait('return_value')

    client1.unregister()
    client2.unregister()
Esempio n. 14
0
def app(request, manager, watcher, bind):
    app = App().register(manager)
    node = Node().register(app)
    watcher.wait('ready')

    child = (App() + Node(port=bind[1], server_ip=bind[0]))
    child.start(process=True)

    node.add('child', *bind)
    watcher.wait('connected')

    def finalizer():
        child.stop()

    request.addfinalizer(finalizer)

    return app
Esempio n. 15
0
    def init(self, args, opts):
        if opts.debug:
            Debugger().register(self)

        if ":" in opts.bind:
            address, port = opts.bind.split(":")
            port = int(port)
        else:
            address, port = opts.bind, 8000

        auto_remote_event = {'increment': '*'}

        node = Node().register(self)
        node.add('peer_name',
                 address,
                 port,
                 auto_remote_event=auto_remote_event)
Esempio n. 16
0
def app(request, manager, watcher, bind):
    app = App().register(manager)
    node = Node().register(app)
    watcher.wait("ready")

    child = App() + Node(port=bind[1], server_ip=bind[0])
    child.start(process=True)

    node.add("child", *bind)
    watcher.wait("connected")

    def finalizer():
        child.stop()

    request.addfinalizer(finalizer)

    return app
Esempio n. 17
0
def test_server_send(app, watcher, manager):
    client1 = App().register(manager)
    node1 = Node().register(client1)
    chan1 = node1.add('client1', *app.bind)
    assert watcher.wait('connected', channel=chan1)

    client2 = App().register(manager)
    node2 = Node().register(client2)
    chan2 = node2.add('client2', *app.bind)
    assert watcher.wait('connected', channel=chan2)

    event = return_value()
    app.server.send(event, app.server.get_socks()[0], no_result=True)
    assert watcher.wait('return_value')
    watcher.clear()
    assert not watcher.wait('return_value')

    client1.unregister()
    client2.unregister()
Esempio n. 18
0
    """hello Event"""


class App(Component):

    def ready(self, client):
        print("Ready!")

    def connected(self, host, port):
        print("Connected to {}:{}".format(host, port))
        print("Try: x = app.fire(hello())")

    def hello(self):
        print("Now try: y = app.fire(remote(hello(), \"test\"))")
        return "Hello World! ({0:d})".format(getpid())


# Setup app1 with a debugger
app = App()
node = Node().register(app)

host = sys.argv[1]
port = int(sys.argv[2])
bind = (host, port)

# Add an address of a node to talk to called "test"
node.add("test", *bind)

# Start app as a thread
app.start()