websocket client测试小工具

690阅读 0评论2022-11-01 jiuniu110
分类:网络与安全

1. 用wscat



点击(此处)折叠或打开

  1. #安装
  2. npm install -g wscat
  3. wscat -c ws://127.0.0.1:8080/
  4. #测试成功会显示如下:
    Connected (press CTRL+C to quit)

2. python3下用socketio脚本来测试


点击(此处)折叠或打开

  1. import time
  2. import socketio

  3. sio = socketio.Client(logger=True, engineio_logger=True)

  4. start_time = None
  5. @sio.event
  6. def connect():
  7.     global start_time
  8.     latency = time.time() - start_time
  9.     print("I'm connected!",latency)

  10. @sio.event
  11. def connect_error(data):
  12.     global start_time
  13.     latency = time.time() - start_time
  14.     print("The connection failed!", latency)

  15. @sio.event
  16. def disconnect():
  17.     global start_time
  18.     latency = time.time() - start_time
  19.     print("I'm disconnected!", latency)

  20. if __name__ == '__main__':
  21.     start_time = time.time()
  22.     try:
  23.         sio.connect('ws://127.0.0.1:8080/')
  24.         sio.wait()
  25.         print("run over")
  26.     except Exception as e:
  27.         latency = time.time() - start_time
  28.         print("latency:", latency)
  29.         print("error: get excption:"+repr(e))




上一篇:mac下gdb调试openssl提示which has no line number information
下一篇:react-scripts start 修改默认端口