Exemple #1
0
def main(argc, argv):
    if argc > 2:
        usage()
        sys.exit(1)

    # Argumentos
    opts = readConf()
    mcastPort = int(opts["mcast_port"])
    mcastAddr = opts["mcast_addr"]
    udpPort = int(opts["udp_port"])
    udpAddr = len(sys.argv)>1 and sys.argv[1] or socket.gethostname()

    # Cria conexao com o multicast e abre udp para resposta
    onlinecalc = OnlineCalcClient(mcastPort,mcastAddr,udpPort,udpAddr)

    # Loop para leitura de comandos
    print "ctrl+c para sair."
    while True:
        try:
            calc = raw_input("> ")
            if calc:
                try:
                    print onlinecalc.run(udpPort,calc)
                except socket.timeout:
                    print "Sem resposta (timeout estourou)"
        except (EOFError,KeyboardInterrupt):
            print ""
            break

    return 0
Exemple #2
0
def main(argc,argv):
    if argc != 3:
        usage()
        sys.exit(1)

    # Argumentos
    serverID,serverFile = argv[1:]
    opts = readConf()
    mcastPort = opts["mcast_port"]
    mcastAddr = opts["mcast_addr"]

    # Cria servidor
    onlinecalc = OnlineCalcServer(serverID,mcastPort,mcastAddr,serverFile)

    # Inicia servidor
    try:
        onlinecalc.start()
        while True:
            raw_input("ctrl+c para sair...")
    except (EOFError,KeyboardInterrupt):
        print "Saindo"
        onlinecalc.quit()

    return 0