Created
April 30, 2020 10:01
-
-
Save Filarius/5474332f2e0a1d1647ce1658dfd55730 to your computer and use it in GitHub Desktop.
Simple example of websocket proxy / tunnel / redirection in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uri = "wss://some_address:3214" | |
s = 'greetings' | |
import asyncio | |
import websockets | |
async def hello(websocket, path): | |
async with websockets.connect(uri) as client: | |
await client.send(s) #optional init on connection start | |
while True: | |
data = await client.recv() | |
await websocket.send(data) | |
start_server = websockets.serve(hello, "localhost", 1234) | |
asyncio.get_event_loop().run_until_complete(start_server) | |
asyncio.get_event_loop().run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment