add a python websocket proxy which works on Linux, while ws proxy_server does not
This commit is contained in:
1
test/compatibility/python/websockets/DOCKER_VERSION
Normal file
1
test/compatibility/python/websockets/DOCKER_VERSION
Normal file
@ -0,0 +1 @@
|
||||
0.0.1
|
8
test/compatibility/python/websockets/Dockerfile
Normal file
8
test/compatibility/python/websockets/Dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM python:3.8.0-alpine3.10
|
||||
|
||||
RUN pip install websockets
|
||||
COPY ws_proxy.py /usr/bin
|
||||
RUN chmod +x /usr/bin/ws_proxy.py
|
||||
|
||||
EXPOSE 8765
|
||||
CMD ["python", "/usr/bin/ws_proxy.py"]
|
20
test/compatibility/python/websockets/makefile
Normal file
20
test/compatibility/python/websockets/makefile
Normal file
@ -0,0 +1,20 @@
|
||||
.PHONY: docker
|
||||
|
||||
NAME := bsergean/ws_proxy
|
||||
TAG := $(shell cat DOCKER_VERSION)
|
||||
IMG := ${NAME}:${TAG}
|
||||
LATEST := ${NAME}:latest
|
||||
BUILD := ${NAME}:build
|
||||
|
||||
docker_test:
|
||||
docker build -t ${BUILD} .
|
||||
|
||||
docker:
|
||||
git clean -dfx
|
||||
docker build -t ${IMG} .
|
||||
docker tag ${IMG} ${BUILD}
|
||||
|
||||
docker_push:
|
||||
docker tag ${IMG} ${LATEST}
|
||||
docker push ${LATEST}
|
||||
docker push ${IMG}
|
43
test/compatibility/python/websockets/ws_proxy.py
Normal file
43
test/compatibility/python/websockets/ws_proxy.py
Normal file
@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# WS server example
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import websockets
|
||||
|
||||
|
||||
async def hello(websocket, path):
|
||||
|
||||
url = REMOTE_URL + path
|
||||
async with websockets.connect(url) as ws:
|
||||
taskA = asyncio.create_task(clientToServer(ws, websocket))
|
||||
taskB = asyncio.create_task(serverToClient(ws, websocket))
|
||||
|
||||
await taskA
|
||||
await taskB
|
||||
|
||||
|
||||
async def clientToServer(ws, websocket):
|
||||
async for message in ws:
|
||||
await websocket.send(message)
|
||||
|
||||
|
||||
async def serverToClient(ws, websocket):
|
||||
async for message in websocket:
|
||||
await ws.send(message)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='websocket proxy.')
|
||||
parser.add_argument('--host', help='Host to bind to.', default='localhost')
|
||||
parser.add_argument('--port', help='Port to bind to.', default=8765)
|
||||
parser.add_argument('--remote_url', help='Remote websocket url', default='ws://localhost:8767')
|
||||
args = parser.parse_args()
|
||||
|
||||
REMOTE_URL = args.remote_url
|
||||
|
||||
start_server = websockets.serve(hello, args.host, args.port)
|
||||
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
asyncio.get_event_loop().run_forever()
|
Reference in New Issue
Block a user