接口测试笔记三

余生颓废 提交于 2020-05-08 14:01:03

上一篇

接口测试笔记二

websocket接口调用

websocket.py

from ws4py.client.threadedclient import WebSocketClient

class CG_Client(WebSocketClient):

  def opened(self):
    req = "Hello, World"
    self.send(req)

  def closed(self, code, reason=None):
    print("Closed down:", code, reason)

  def received_message(self, resp):
    result = str(resp)
    print(" 返回 "+result)

if __name__ == '__main__':
  ws = None
  try:
    ws = CG_Client('ws://echo.websocket.org')
    ws.connect()
    ws.run_forever()
  except KeyboardInterrupt:
    ws.close()

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!