test_client.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. import sys
  3. sys.path.append("../ServerCore")
  4. import socket # noqa
  5. import json # noqa
  6. from JSONStreamParser import JSONStreamParser # noqa
  7. import argparse # noqa
  8. def send_request(host, port, datatype, position, data):
  9. parser = JSONStreamParser()
  10. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  11. s.connect((host, port))
  12. message_object = {}
  13. if datatype is not None:
  14. message_object['datatype'] = datatype
  15. if position is not None:
  16. message_object['position'] = position
  17. if data is not None:
  18. message_object['data'] = data
  19. s.sendall(json.dumps(message_object).encode())
  20. while parser.isQueueEmpty():
  21. parser.appendRawData(s.recv(4096))
  22. print("received data:\n", parser.popAsJSON())
  23. s.close()
  24. def main():
  25. parser = argparse.ArgumentParser(
  26. description="tester for the voxel Server protocoll")
  27. parser.add_argument('--datatype')
  28. parser.add_argument('--position', nargs=3, type=int)
  29. parser.add_argument('--data')
  30. args = parser.parse_args()
  31. send_request('127.0.0.1', 5050, args.datatype, args.position, args.data)
  32. if __name__ == "__main__":
  33. main()