Skip to content

Commit

Permalink
wssserver tool should accept port parameter
Browse files Browse the repository at this point in the history
Default doesn't agree with `WebsocketClient` sample, should be 8000
  • Loading branch information
mikee47 committed Jun 22, 2024
1 parent 6827474 commit d0af2b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sming/Components/Network/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ endif

# Websocket Server
CACHE_VARS += WSSERVER_PORT
WSSERVER_PORT ?= 9999
WSSERVER_PORT ?= 8000
.PHONY: wsserver
wsserver: ##Launch a simple python Websocket echo server for testing client applications
$(info Starting Websocket server for TESTING)
Expand Down
10 changes: 7 additions & 3 deletions Sming/Components/Network/tools/wsserver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

import argparse
import asyncio
from websockets.server import serve
import logging
Expand All @@ -8,13 +9,16 @@ async def echo(websocket):
async for message in websocket:
await websocket.send(message)

async def main():
async def main(port: int):
logging.basicConfig(
format="%(asctime)s %(message)s",
level=logging.DEBUG,
)
async with serve(echo, None, 8000):
async with serve(ws_handler=echo, port=port):
await asyncio.Future() # run forever

if __name__ == "__main__":
asyncio.run(main())
parser = argparse.ArgumentParser(description='Simple websocket server')
parser.add_argument('port', help='Port number (default 8000)', type=int, default=8000)
args = parser.parse_args()
asyncio.run(main(args.port))

0 comments on commit d0af2b6

Please sign in to comment.