【发布时间】:2016-09-19 02:03:58
【问题描述】:
我想通过asyncio和websockets连接到一个websocket,格式如下图。我怎样才能做到这一点?
from websockets import connect
class EchoWebsocket:
def __init__(self):
self.websocket = self._connect()
def _connect(self):
return connect("wss://echo.websocket.org")
def send(self, message):
self.websocket.send(message)
def receive(self):
return self.websocket.recv()
echo = EchoWebsocket()
echo.send("Hello!")
print(echo.receive()) # "Hello!"
【问题讨论】:
标签: python python-3.x websocket python-3.5 python-asyncio