python一個簡單的websocket測試客戶端


朋友發的,之前在網上一直沒找着,先記着

 

#!/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())


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM