sdroege/async-tungstenite

Example how to use with HTTP server

Frando opened this issue · 2 comments

Hi,
thanks for this library! I'm wondering if there's any existing example on how to couple this with e.g. static file serving over the same port? I'd want to serve static files, and have a /ws route to be handled by async-tungstenite. Are there any examples on how to do this e.g. with tide? Thanks!

Tide would probably do the WebSocket handshake (which happens via HTTP) itself already, so you'd have to take care of that. See https://docs.rs/tungstenite/0.10.1/tungstenite/handshake/server/fn.create_response.html for that.

Once the WebSocket handshake is done you would use one of the from_XXX constructors of WebSocketStream here on an AsyncRead+AsyncWrite that represents the HTTP connection after the handshake (the body basically): https://docs.rs/async-tungstenite/0.4.2/async_tungstenite/struct.WebSocketStream.html

I don't know the Tide API, but with hyper's upgrade API this is relatively easy to do. Probably more a question for the Tide developers :) Maybe @yoshuawuyts has some suggestions.

Any progress here? I guess this can be closed though, there's nothing specifically to do here for this repository.