码迷,mamicode.com
首页 > 编程语言 > 详细

python一个简单的websocket测试客户端

时间:2018-05-01 00:36:38      阅读:482      评论:0      收藏:0      [点我收藏+]

标签:bottom   import   asyncio   star   style   一个   Python一   pad   run   

朋友发的,之前在网上一直没找着,先记着

 

#!/usr/bin/env python

import asyncio
import websockets
import json

async def test_ws_quote():
    async with websockets.connect(‘ws://192.168.0.205:8888/quote/quote‘) as websocket:
        req = {"protocol":"history_req",‘code‘:‘XAGODS‘,‘type‘:‘MINUTE‘,‘start_pos‘:‘0‘,‘pos_num‘:‘10‘}
        await websocket.send(json.dumps(req))
   
        while True:
            quote = await websocket.recv()
            print(quote)

asyncio.get_event_loop().run_until_complete(test_ws_quote())

python一个简单的websocket测试客户端

标签:bottom   import   asyncio   star   style   一个   Python一   pad   run   

原文地址:https://www.cnblogs.com/luhouxiang/p/8975328.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!