原文:AioWebSocket实现python异步接收B站直播弹幕
import ssl
import websocket
import asyncio
import zlib
import json
import _thread as thread
import time
import requests
class WebsocketClient(object):
"""docstring for WebsocketClient"""
def __init__(self, address, send_message):
super(WebsocketClient, self).__init__()
self.address = address
self.send_message = send_message
def on_message(self, ws, message):
printDM(message)
def on_error(self, ws, error):
print("### 报错:", error)
def on_close(self, ws,x,y):
print("### 已关闭###")
print(x,y)
def on_open(self, ws):
print("开始连接")
def run(*args):
self.ws.send(self.send_message)
print(self.send_message)
# self.ws.close()
hb='00 00 00 10 00 10 00 01 00 00 00 02 00 00 00 01'
def sendHeartBeat():
while True:
time.sleep(