ConnectionTest2008.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """
  2. echo "执行:进入调试" \
  3. && project_path="/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01" \
  4. && cd ${project_path} \
  5. && sudo docker exec -it sri-dino-pyserver01 bash
  6. python3 /home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01/lib/ConnectionTest.py
  7. """
  8. import socket
  9. import struct
  10. import traceback
  11. import time
  12. import sys
  13. import importlib
  14. # --- for linux
  15. sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/sri-dino-pyserver01')
  16. sys.path.append('/home/sri/repositories/repositories/sri-project.demo-py/3rdparty')
  17. # host, port = '127.0.0.1', 20916
  18. host, port = '127.0.0.1', 20917
  19. # --- for windows
  20. # sys.path.append(r'E:\casper\repositories\repositories\sri-project.demo-py\sri-server-bg03')
  21. # sys.path.append(r'E:\casper\repositories\repositories\sri-project.demo-py\3rdparty')
  22. # host, port = '58.34.94.178', 20916
  23. # host, port = '58.34.94.178', 20916
  24. # host, port = '58.34.94.178', 20917
  25. # --- import
  26. protobuf = importlib.import_module(f"xprotobuf.protocol_pb2")
  27. methods = importlib.import_module(f"xlib")
  28. def test():
  29. head_sequence = '<hh' # 字节序规则
  30. head_size = struct.calcsize(head_sequence)
  31. try:
  32. client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  33. # client.bind(('localhost', port))
  34. client.connect((host, port))
  35. # --- send 2008
  36. head = 2008, 0
  37. head_bytestream = struct.pack(head_sequence, *head)
  38. send_bytestream = head_bytestream
  39. print(f"Sent data: {send_bytestream}")
  40. client.sendall(send_bytestream)
  41. while True:
  42. pass
  43. except Exception as exception:
  44. print(f"#exception: {exception.__class__.__name__}")
  45. print(f"#traceback: {traceback.format_exc()}")
  46. finally:
  47. client.close()
  48. if __name__ == "__main__":
  49. test()