Python Library Socket Protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

socket_protocol_server.py 785B

123456789101112131415161718192021222324252627282930
  1. import sys
  2. sys.path.append('../..')
  3. import report
  4. import socket_protocol
  5. import tcp_socket
  6. import time
  7. def time_callback(msg):
  8. if msg.get_status() == socket_protocol.STATUS_OKAY:
  9. return socket_protocol.STATUS_OKAY, time.asctime()
  10. else:
  11. return socket_protocol.STATUS_OPERATION_NOT_PERMITTED, None
  12. report.stdoutLoggingConfigure(log_name_lvl=[('root', 'INFO'), ])
  13. s = tcp_socket.tcp_server_stp('127.0.0.1', 17017)
  14. sp = socket_protocol.pure_json_protocol(s, channel_name='example_server')
  15. sp.register_callback(socket_protocol.SID_READ_REQUEST, 0, time_callback)
  16. i = 0
  17. while not s.is_connected() and i <= 20:
  18. i += 1
  19. time.sleep(.1) # wait for a connection
  20. i = 0
  21. while s.is_connected() and i <= 20:
  22. i += 1
  23. time.sleep(.1) # wait for disconnect