- Asynchronous with python asyncio
- Multiple clients
- Passes autobahn tests 1-10 (11-13 needs compression extension)
- All control frames with status and reason
- Heartbeat
python3.6 -m venv myproject
source myproject/bin/activate
pip install asws3
from websocket.client import Client
from websocket.server import WebSocketServer
from websocket.stream.reader import WebSocketReader
loop = asyncio.get_event_loop()
socket = WebSocketServer("localhost", 3001, loop=loop)
@socket.connection
async def on_connection(client: Client):
print(f'Connection from {client.addr, client.port}')
print(f'All clients: {socket.clients}')
@client.message
async def on_message(reader: WebSocketReader):
await client.writer.send(await reader.get())
with socket as server:
print(f'Serving on {server.sockets[0].getsockname()}')
loop.run_forever()
loop.close()
- Websocket Extentions
- Test with random data