コード例 #1
0
ファイル: lab1.py プロジェクト: akshaykumar90/Labs
    # Start server thread listening to messages
    listen_thread = threading.Thread(name="listen_thread", target=mp.receive_message)
    listen_thread.start()

    CLIENT_PROMPT = "[&]"

    while True:
      try:
        inp = raw_input(CLIENT_PROMPT)
      except EOFError:
        break
      sinput = inp.split()
      cmd = sinput[0]
      if cmd == 'dump':
        # Receive ALL outstanding messages
        msg = mp.receive()
        while msg is not None:
          logger_messages.append(msg)
          msg = mp.receive()
        
        # Sort the logger messages according to their timestamp
        logger_messages.sort(cmp=lambda x,y: cs.compare(x.timestamp, y.timestamp))

        # Dump the messages to a file
        fp = open("logger.txt", "w")
        for item in logger_messages:
          fp.write(item.timestamp + "-" + item.src + "-" + item.kind + "\n")
        fp.close()
      else:
        print "usage: dump"
  else:
コード例 #2
0
ファイル: lab0.py プロジェクト: akshaykumar90/Labs
        # Start server thread listening to messages
        listen_thread = threading.Thread(name="listen_thread", target=mp.receive_message)
        listen_thread.start()

        CLIENT_PROMPT = "[&]"

        while True:
            try:
                inp = raw_input(CLIENT_PROMPT)
            except EOFError:
                break
            sinput = inp.split()
            cmd = sinput[0]
            if cmd == "send":
                dest = sinput[1]
                kind = sinput[2]
                txt = raw_input("Message:")
                new_msg_s = TimeStampedMessage(mp.local_name, dest, kind, txt)
                mp.send(new_msg_s)
            elif cmd == "receive":
                new_msg_r = mp.receive()
                if new_msg_r is not None:
                    print new_msg_r.src, "|", new_msg_r.kind, "|", new_msg_r.data
                else:
                    print "No new messages"
            else:
                print "usage: send <dest> <kind> | receive"
    else:
        print >> sys.stderr, "usage: lab0.py <config_filename> <local_name>"