Exemple #1
0
def create_ofg_server(port, recv_callback):
    """Starts a server which listens for OFG clients on the specified port.

    @param port  the port to listen on
    @param recv_callback  the function to call with received message content
                         (takes two arguments: transport, msg)

    @return returns the new LTTwistedServer
    """
    from ltprotocol.ltprotocol import LTTwistedServer
    server = LTTwistedServer(OFG_PROTOCOL, recv_callback)
    server.listen(port)
    return server
def create_vns_server(port, recv_callback, new_conn_callback, lost_conn_callback, verbose=True):
    """Starts a server which listens for VNS clients on the specified port.

    @param port  the port to listen on
    @param recv_callback  the function to call with received message content
                         (takes two arguments: transport, msg)
    @param new_conn_callback   called with one argument (a LTProtocol) when a connection is started
    @param lost_conn_callback  called with one argument (a LTProtocol) when a connection is lost
    @param verbose        whether to print messages when they are sent

    @return returns the new LTTwistedServer
    """
    server = LTTwistedServer(VNS_PROTOCOL, recv_callback, new_conn_callback, lost_conn_callback, verbose)
    server.listen(port)
    return server
Exemple #3
0
    if len(sys.argv) < 2:
        print >> sys.stderr, "usage: ./test_ltprotocol.py TYPE"
        sys.exit(-1)

    what = sys.argv[1]
    if what != "client" and what != "server":
        print >> sys.stderr, "TYPE must be client or server"
        sys.exit(-1)

    # periodically sends some messages
    def periodic_send(proto):
        if proto.connected:
            print 'sending ...'
            proto.send(NumMsg(200))
            proto.send(StrMsg("hello world!"))
            proto.send(NumMsg(7))
            reactor.callLater(1, lambda : periodic_send(proto))

    if what == "client":
        client = LTTwistedClient(TEST_PROTOCOL,
                                 lambda p, m : print_ltm('client', p, m))
        client.connect('127.0.0.1', 9999)
    else:
        server = LTTwistedServer(TEST_PROTOCOL,
                                 lambda p, m : print_ltm('server', p, m),
                                 periodic_send,
                                 print_disconnect)
        server.listen(9999)

    reactor.run()