Skip to content

regiontog/asws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Features

Installing

python3.6 -m venv myproject
source myproject/bin/activate

pip install asws3

Usage

Basic echo server

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()

Documentation

Examples

See some example servers

TODO

  • Websocket Extentions
  • Test with random data