Beispiel #1
0
def connectSession(connection, sessionid):
    data = "session flags=add number %s" % str(sessionid)
    result, msg_cls, flags, tlv_data = \
            TLVHelper.parse_tlv_stringlist(data.split())
    msg = msg_cls.pack(flags, tlv_data)
    connection.socket.sendall(msg)
Beispiel #2
0
        usage(err=1)

    for msg_type in connection.msg_handler.handled_msg_types:
        connection.msg_handler.set_msg_callback(msg_type, msg_callback)

    if not opt.session is None:
        connectSession(connection, str(opt.session))

    # serve forever (or until CTRL+C is pressed)
    while True:
        try:
            data = sys.stdin.readline().split()
            if len(data) == 0:
                if opt.once and got_answer:
                    time.sleep(0.1)
                    break
                time.sleep(0.1)
                continue
            result, msg_cls, flags, tlv_data = \
                    TLVHelper.parse_tlv_stringlist(data)
            if result:
                msg = msg_cls.pack(flags, tlv_data)
                #print('%s: sending data: %s' % (str(time.time()), str(msg)),
                #    file=sys.stderr)
                connection.socket.sendall(msg)
        except KeyboardInterrupt:
            print("CTRL+C pressed")
            sys.exit(0)

    sys.exit(0)