Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test with unix port = too slow #3

Open
picpic020960 opened this issue Mar 4, 2022 · 1 comment
Open

test with unix port = too slow #3

picpic020960 opened this issue Mar 4, 2022 · 1 comment

Comments

@picpic020960
Copy link

Bonjour ,
test with unix port on local machine but it is very slow.
With ESP32 it's fast.
One trick ?
thank's for help

@marcidy
Copy link
Owner

marcidy commented Mar 4, 2022

Salut, I'm sorry, I don't know much about the unix port, i dont use it. I use python websockets based server on unix to interface. Something like

import pathlib
import logging
import asyncio
from collections import defaultdict
import json
import websockets


devices = {}
pages = defaultdict(set)


async def add_page(websocket, path):
    print(f"Page connected to {path}")
    pages[path].add(websocket)
    try:
        async for msg in websocket:
            if path in devices:
                await devices[path].send(msg)
    finally:
        pages[path].remove(websocket)
        print("Page Left")


async def add_device(websocket, path):
    print(f"Device connected: {path}")
    if path in devices:
        ws = devices.pop(path)
        await ws.close()
    devices[path] = websocket

    try:
        async for msg in websocket:
            logging.info(path + "/" + msg)
            if len(pages[path]) > 0:
                asyncio.gather(*[pg.send(msg) for pg in pages[path]])
    finally:
        if path in devices:
            devices.pop(path)
        await websocket.close()


page_server = websockets.serve(add_page, '127.0.0.1', 7770,
                               compression=None,
                               ping_interval=None,
                               ping_timeout=None)

device_server = websockets.serve(add_device, '0.0.0.0', 7777,
                                 compression=None,
                                 ping_interval=None,
                                 ping_timeout=None)

if __name__ == "__main__":
    logging.basicConfig(filename="stuff.log",
                        format='%(asctime)s %(message)s',
                        level=logging.INFO)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(device_server)
    loop.run_until_complete(page_server)
    loop.run_forever()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants