Skip to content

Instantly share code, notes, and snippets.

@Filarius
Created April 30, 2020 10:01
Show Gist options
  • Save Filarius/5474332f2e0a1d1647ce1658dfd55730 to your computer and use it in GitHub Desktop.
Save Filarius/5474332f2e0a1d1647ce1658dfd55730 to your computer and use it in GitHub Desktop.
Simple example of websocket proxy / tunnel / redirection in Python
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