Share tcp port between axum and tcp server #3146
-
SummaryIs there any way to have normal tcp connections and an axum http server on the same port? I know it is possible to make your own listener, accept clients, then forward to axum to handle the requests, but is there a way to detect if the tcp connection is an http request? Maybe there is a method that attempts to handle a tcp connection but returns an error along with the socket/stream + any read data indicating that the connection was not an http request? axum version=0.8.1 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If I understand the question correctly, you want to run an application on one port and handle the connection with axum if it's HTTP and somehow else if it is not? If so, I really think you don't want to do that, just use two different ports for the two different services. You might also want to look if a reverse proxy like nginx cannot do things like that if you need to use only one port because of firewall or something. If you really need to do it, you might try implementing your own Or if your other protocol cannot contain arbitrary data from the start, you can just buffer the first 4 bytes to make sure they are |
Beta Was this translation helpful? Give feedback.
If I understand the question correctly, you want to run an application on one port and handle the connection with axum if it's HTTP and somehow else if it is not? If so, I really think you don't want to do that, just use two different ports for the two different services. You might also want to look if a reverse proxy like nginx cannot do things like that if you need to use only one port because of firewall or something.
If you really need to do it, you might try implementing your own
Listener
which saves any data and use something like in the example ofserve-with-hyper
and ifhyper
errors out you can call the other service.Or if your other protocol cannot contain arbitrary data from th…