Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Possible to use to proxy websockets? #72

Open
buddyroo30 opened this issue May 15, 2020 · 1 comment
Open

Possible to use to proxy websockets? #72

buddyroo30 opened this issue May 15, 2020 · 1 comment

Comments

@buddyroo30
Copy link

I'm trying to create a reverse proxy in Python, and got it working for the normal HTTP traffic, but can't figure out how to proxy web sockets. I was hoping flask_sockets could do this, but I can't figure out how to do it. Is it possible, and how would you do that? I tried to do like this, e.g. (using, in addition, websocket):

@sockets.route('/2/')
@sockets.route('/2/path:path')
def proxy_socket(ws_in):
path = ws_in.environ['QUERY_STRING']
message = ws_in.receive()
ws_path = f'{SITE_NAME2_WS}{path}'
ws = create_connection(ws_path)
ws.send(message)
result = ws.recv()
while not ws.closed:
ws_in.send(result)
ws.close()

But this didn't work, I'm able to read messages sent on ws_in, but it fails to connect and send them to the backend. Anyway, if you have any guidance on how to proxy websockets in Python, I'd appreciate it. Thanks.

@nmz787
Copy link

nmz787 commented Aug 20, 2021

the lack of indentation makes your code snippet basically illegible

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants