Http + ws on same port

Without using nginx or some type of port forwarding, is it possible to run http and websocket on the same port?

This requires something called ‘upgrading’ a http connection, to take it from http to websocket.

The closest I have found is this blog post:

but I don’t see how to get from the code fragment to actual working code. (Also, it seems to be using hyper 0.11 instead of hyper 0.12).

Question:

Is there working code anywhere of http + websocket on same port?

actix-web (https://actix.rs/docs/websockets/) let you do that easily.

Does this upgrade example from hyper help?

I saw this example before, but could not figure out where the websocket is. I found nothing searching that page for “websocket” and “ws”

I’m new to the rust ecosystem. Can you please point out:

  1. what struct/‘noun’ is websocket in that example
  2. where the open, send, recv are?

Thanks!

Yes, it doesn’t show the WS part, only the upgrade part.

The second part to look at is something like this: https://docs.rs/websocket/0.20.3/websocket/server/upgrade/index.html

(Sorry for the terse reply, hopefully someone can give a more detailed answer)