From 051c34bc5dd79f37e09b5ea88b8e5a46bb6cf60c Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Sat, 8 Jun 2019 09:46:26 -0700 Subject: [PATCH] Add test/compatibility folder with small servers and clients written in different languages and different libraries to test compatibility. --- .../compatibility/python/websockets/README.md | 30 +++++++++++++++++++ .../python/websockets/echo_server.py | 22 ++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 test/compatibility/python/websockets/README.md create mode 100644 test/compatibility/python/websockets/echo_server.py diff --git a/test/compatibility/python/websockets/README.md b/test/compatibility/python/websockets/README.md new file mode 100644 index 00000000..0e214e70 --- /dev/null +++ b/test/compatibility/python/websockets/README.md @@ -0,0 +1,30 @@ +# Clients + +## ws + +``` +$ ws connect ws://127.0.0.1:8765 +Type Ctrl-D to exit prompt... +Connecting to url: ws://127.0.0.1:8765 +> ws_connect: connected +Uri: / +Handshake Headers: +Connection: Upgrade +Date: Sat, 08 Jun 2019 16:43:29 GMT +Sec-WebSocket-Accept: kPCNwGa97y+7NWdAvHi/7/rA8AE= +Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=15; client_max_window_bits=15 +Server: Python/3.7 websockets/7.0 +Upgrade: websocket +Received 13 bytes +ws_connect: received message: > Welcome ! +ws_connect: connection closed: code 1006 reason Abnormal closure +``` + +## wscat + +``` +$ ./node_modules/.bin/wscat -c ws://127.0.0.1:8765 +connected (press CTRL+C to quit) +< > Welcome ! +disconnected (code: 1006) +``` diff --git a/test/compatibility/python/websockets/echo_server.py b/test/compatibility/python/websockets/echo_server.py new file mode 100644 index 00000000..f8916276 --- /dev/null +++ b/test/compatibility/python/websockets/echo_server.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +# WS server example + +import asyncio +import websockets + +async def hello(websocket, path): + await websocket.send(f"> Welcome !") + + name = await websocket.recv() + print(f"< {name}") + + greeting = f"Hello {name}!" + + await websocket.send(greeting) + print(f"> {greeting}") + +start_server = websockets.serve(hello, 'localhost', 8765) + +asyncio.get_event_loop().run_until_complete(start_server) +asyncio.get_event_loop().run_forever()