Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] add websocket support? #222

Open
blurskye opened this issue Dec 6, 2024 · 4 comments
Open

[enhancement] add websocket support? #222

blurskye opened this issue Dec 6, 2024 · 4 comments

Comments

@blurskye
Copy link

blurskye commented Dec 6, 2024

it seems websocket do not work(yet)

2024-12-06T04:05:52.499856Z  INFO Listen IPv4
2024-12-06T04:05:52.499894Z  INFO Listen port: 5126
2024-12-06T04:05:52.499901Z  INFO Cache is disabled
2024-12-06T04:05:52.499943Z  INFO Registering application blurskye.dev (websocket)
2024-12-06T04:05:52.499969Z  INFO Platform verifier with rustls is used for the connection to backend applications
2024-12-06T04:05:52.499996Z  INFO rpxy proxy service for 0.0.0.0:5126 started
2024-12-06T04:05:52.500105Z  INFO Start TCP proxy serving with HTTP request for configured host names
2024-12-06T04:05:55.807197Z ERROR No matching backend app
2024-12-06T04:05:55.807234Z  INFO {ip-vps} <- {ip-home} -- GET / HTTP/1.1 -- 503 Service Unavailable --  "Python/3.12 websockets/14.1", "" ""
2024-12-06T04:05:57.244001Z ERROR No matching backend app
2024-12-06T04:05:57.244035Z  INFO {ip-vps} <- {ip-home} -- GET / HTTP/1.1 -- 503 Service Unavailable --  "Python/3.12 websockets/14.1", "" ""
2024-12-06T04:05:58.131175Z ERROR No matching backend app
2024-12-06T04:05:58.131212Z  INFO {ip-vps} <- {ip-home} -- GET / HTTP/1.1 -- 503 Service Unavailable --  "Python/3.12 websockets/14.1", "" ""
@Gamerboy59
Copy link
Contributor

A good idea in general to allow upgrading from simple tcp to websocket. I just see problems when you have defined multiple upstreams, then rpxy has to make sure that the websocket connection stays alive to the specific upstream.

@junkurihara
Copy link
Owner

junkurihara commented Dec 6, 2024

Rpxy itself supports upgrading to websocket via http 101 switching protocols, which is actually the only use case of websocket in the context of http. If we consider upgrading directly from tcp, then we have to or should redesign rpxy as more general purpose reverse proxy supporting http’s underlying protocols, i.e., tcp, tls, quic, etc.

@xkr47
Copy link
Contributor

xkr47 commented Dec 12, 2024

What is this "websocket from tcp" thing you are talking about?
Also, I am using websockets succesfully through rpxy no problems whatsoever. Based on the log messages it seems @blurskye just forgot to configure the Host header of their request correctly..

@blurskye
Copy link
Author

blurskye commented Dec 14, 2024

wdym host header? i just tried this

import asyncio
import websockets

async def hello(websocket):
    await websocket.send("Hello from server!")
    while True:
        try:
            message = await websocket.recv()
            print(f"Received: {message}")
            await websocket.send(f"Server received: {message}")
        except websockets.ConnectionClosed:
            break

async def main():
    async with websockets.serve(hello, "127.0.0.1", 5125):
        print("WebSocket server running on ws://127.0.0.1:5125")
        await asyncio.Future()  # run forever

asyncio.run(main())

(forward from rpxy to 0.0.0.0)
and python -m websockets ws://<ip addr>:5125
note: you need websockets module installed @xkr47

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

No branches or pull requests

4 participants