Ejemplo n.º 1
0
def main():
    xsub_port = '5556'
    xpub_port = '5557'
    broker = Broker(xsub_port, xpub_port)
    broker.handler()
    while True:
        pass
Ejemplo n.º 2
0
import time
import argparse  # for command line parsing


def parseCmdLineArgs():
    # parse the command line
    parser = argparse.ArgumentParser()
    # add optional arguments
    parser.add_argument("-b",
                        "--brokers",
                        type=str,
                        help='all brokers ip address')
    parser.add_argument("-i", "--ip", type=str, help='self ip address')
    # parse the args
    args = parser.parse_args()
    return args


if __name__ == '__main__':
    args = parseCmdLineArgs()
    brokerIPs = args.brokers
    ip = args.ip
    brokerIPs = brokerIPs.split('-')
    broker = Broker(brokerIPs, ip, '5556', '5557', '5558', '5559', '6000',
                    '6001', '6002', '6003')

    broker.handler()
    while True:
        pass
Ejemplo n.º 3
0
def parse(argv):
    opt = argv[0]
    global pub
    global broker
    global sub
    if opt == 'pub':
        if argv[1] == '-r' and argv[3] == '-P' and argv[5] == '-t':
            if pub is None:
                address = argv[2]
                port = argv[4]
                topic = argv[6]
                pub = Publisher(address, port, topic)
                if pub.register_handler():
                    return True
                else:
                    return False
            else:
                print('You already registered a publisher.')
                return False
        elif argv[1] == 'send' and argv[2] == '-t' and argv[4] == '-p':
            if pub is None:
                print('Please register a publisher firstly.')
                return False
            else:
                topic = argv[3]
                publication = ' '.join(argv[5:])
                pub.send_pub(topic, publication)
        elif argv[1] == '-d':
            if pub is None:
                print('Please register a publisher firstly.')
                return False
            else:
                topic = argv[2]
                pub.drop_topic(topic)
        elif argv[1] == 'shutoff':
            if pub is None:
                print('Please register a publisher firstly.')
                return False
            else:
                pub.shutoff()
                return True
        else:
            print('Illegal command.')
            return False

    elif opt == 'broker':
        if argv[1] == '-l':
            xsubport = argv[2]
            xpubport = argv[3]
            broker = Broker(xsubport, xpubport)
            broker.handler()
        else:
            print('Illegal command.')
            return False

    elif opt == 'sub':
        if argv[1] == '-r' and argv[3] == '-P' and argv[5] == '-t' and argv[
                7] == '-h':
            address = argv[2]
            port = argv[4]
            topic = argv[6]
            count = argv[8]
            sub = Subscriber(address, port, topic, count)
            sub.prepare()
            sub.handler()
        else:
            print('Illegal command.')
            return False
    else:
        print('Illegal command.')
        return False