read_messages.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # GNU General Public License
  2. # This script is for developers of VCStudio. This one is for reading messages.
  3. import sys
  4. import datetime
  5. # Fisrt we need to know what mode are we testing.
  6. print(" VCStudio Read Messages.")
  7. print(" Modes: r [Render], m [Multiuser]")
  8. if len(sys.argv) > 2:
  9. mode = sys.argv[2]
  10. print("Mode: "+mode)
  11. else:
  12. mode = input("Mode: ")
  13. import socket
  14. if mode == "r":
  15. UDP_IP = "127.0.0.1"
  16. UDP_PORT = 54545
  17. elif mode == "m":
  18. UDP_IP = "255.255.255.255"
  19. UDP_PORT = 54545
  20. else:
  21. print("There is no mode: "+mode)
  22. exit()
  23. prev = ""
  24. while True:
  25. try:
  26. sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  27. sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  28. sock.bind((UDP_IP, UDP_PORT))
  29. sock.settimeout(0.05)
  30. data, addr = sock.recvfrom(1024)
  31. data = data.decode('utf8')
  32. seconds_format = "%H:%M:%S"
  33. time = datetime.datetime.strftime(datetime.datetime.now(), seconds_format)
  34. if prev != str(data):
  35. print(time+" | "+str(data))
  36. prev = str(data)
  37. sock.close()
  38. except:
  39. pass