예제 #1
0
 def testA(self):
     """Note that all test method names must begin with 'test.'"""
     con = Connection("127.0.0.1", 10000)
     con.open()
     con.send("Can you hear me?")
     con.close()
     con.open()
     con.send("Can you hear me now?")
     con.close()
     assert 5 == 5, "bar() not calculating values correctly"
예제 #2
0
def main():
    """\internal
    \brief Parse command line options and start the server.
    """
    global server, domain_server, node_id, neighbours, local_ts, options

    options = getOptions()

    if not options.daemon:
        import subprocess
        subprocess.Popen("linda_monitor", shell=True)
        #pid = os.fork()
        #if pid != 0:
        #    from monitor import monitor
        #    return monitor.Thread(options.port).run()

    _linda_server.init()

    if options.peer:
        options.peer.append("127.0.0.1")  # always allow local connections.

    def lookupname(addr):
        try:
            addr, r = addr.split("/")
        except ValueError:
            r = "32"

        addr = socket.gethostbyname(addr)
        if addr.count(".") != 3:
            print "%s is not in n.n.n.n[/r] format" % (addr + "/" + r)
            sys.exit(0)
        return addr + "/" + r

    node_id = "N" + guid.generate()
    _linda_server.setnodeid(node_id)

    if options.mdns and not options.disable_mdns:
        import mdns
        s = mdns.connect()
        if s:
            options.connect = s[0]
            options.connectport = s[1]

    if options.connect is not None and len(options.connect) > 0:
        if options.connectport:
            con = zip(options.connect, options.connectport) + [
                (x, 2102) for x in options.connect[len(options.connectport):]
            ]
        else:
            con = zip(options.connect, [2102 for _ in options.connect])
        assert len(con) == len(options.connect)
        i = 0
        while True:
            svr, port = con[i]
            s = _linda_server.connect("%s:%s" % (svr, port))
            if s is None:
                if i < len(con) - 1:
                    i += 1
                    continue
                else:
                    print "Unable to connect to server %s:%i." % (svr, port)
                    sys.exit(-1)

            s = Connection(s)
            s.type = None

            s.send(None, (get_node_id, ))
            node = s.recv()[2]
            assert utils.isNodeId(node), repr(node)

            s.send(None, (my_name_is, node_id))
            s.recv()
            s.type = "SERVER"

            s.name = node
            neighbours[node] = s
            connections.sockets.append(s)
            break

    local_ts.newTupleSpace("UTS")

    while True:
        try:
            socket_watcher()
        except KeyboardInterrupt:
            cleanShutdown()
            raise
        break
예제 #3
0
def main():
    """\internal
    \brief Parse command line options and start the server.
    """
    global server, domain_server, node_id, neighbours, local_ts, options

    options = getOptions()

    if not options.daemon:
        import subprocess
        subprocess.Popen("linda_monitor", shell=True)
        #pid = os.fork()
        #if pid != 0:
        #    from monitor import monitor
        #    return monitor.Thread(options.port).run()

    _linda_server.init()

    if options.peer:
        options.peer.append("127.0.0.1") # always allow local connections.

    def lookupname(addr):
        try:
            addr,r = addr.split("/")
        except ValueError:
            r = "32"

        addr = socket.gethostbyname(addr)
        if addr.count(".") != 3:
            print "%s is not in n.n.n.n[/r] format" % (addr+"/"+r)
            sys.exit(0)
        return addr+"/"+r

    node_id = "N"+guid.generate()
    _linda_server.setnodeid(node_id)

    if options.mdns and not options.disable_mdns:
        import mdns
        s = mdns.connect()
        if s:
            options.connect = s[0]
            options.connectport = s[1]

    if options.connect is not None and len(options.connect) > 0:
        if options.connectport:
            con = zip(options.connect, options.connectport) + [(x, 2102) for x in options.connect[len(options.connectport):]]
        else:
            con = zip(options.connect, [2102 for _ in options.connect])
        assert len(con) == len(options.connect)
        i = 0
        while True:
            svr, port = con[i]
            s = _linda_server.connect("%s:%s" % (svr, port));
            if s is None:
                if i < len(con)-1:
                    i += 1
                    continue
                else:
                    print "Unable to connect to server %s:%i." % (svr, port)
                    sys.exit(-1)

            s = Connection(s)
            s.type = None

            s.send(None, (get_node_id, ))
            node = s.recv()[2]
            assert utils.isNodeId(node), repr(node)

            s.send(None, (my_name_is, node_id))
            s.recv()
            s.type = "SERVER"

            s.name = node
            neighbours[node] = s
            connections.sockets.append(s)
            break

    local_ts.newTupleSpace("UTS")

    while True:
        try:
            socket_watcher()
        except KeyboardInterrupt:
            cleanShutdown()
            raise
        break
예제 #4
0
 def testSendingOverClosedConnectionRaisesNetworkException(self):
     con = Connection(self.config["server"]["ip"],
                      self.config["server"]["port"])
     with self.assertRaises(NetworkException):
         con.send("Hello world")