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

tokio-tungstenite and hyper server #51

Closed
goriunov opened this issue Nov 4, 2018 · 6 comments
Closed

tokio-tungstenite and hyper server #51

goriunov opened this issue Nov 4, 2018 · 6 comments

Comments

@goriunov
Copy link

goriunov commented Nov 4, 2018

Hi, i am writing a server where i need websocket connections. I have a whole server written in hyper. How can i add tokio-tungstenite to the hyper server ?

Would be good if you could show a simple example of that as i am still a newbie in Rust :)

Thank you.

@ghost
Copy link

ghost commented Jan 15, 2019

Here's an example of how to do a WebSocket upgrade with Hyper.

https://github.com/krzysztofwos/hyper-websocket-upgrade

I am evaluating tokio-tungstenite for my next project. The problem that I am experiencing right now is that there seems to be no way to gracefully initiate the closing handshake from the server side with a custom close code and close reason (something that's possible with tungstenite), because when I get a sink and a stream I no longer have any interface to send a closing frame. Any ideas on how to address this?

@daniel-abramov
Copy link
Member

daniel-abramov commented Jan 15, 2019

Thanks for providing the example for others, unfortunately we did not have time to check the hyper implementation and prepare another example.

As for the closing of the websocket connection -- you're right and we also thought about that. I think that one of the possible solutions may be an addition of close message to the Message enum, currently the Message allows you to construct binary and text messages as well as Ping and Pong messages, but since Close message is kind of special, we did not add it do the enum yet. Perhaps it would make sense to add the possibility to send the Close message as Message::Close(Reason).

We actually discussed that once here: #45

But somehow did not get to the point where we had time to do the change (it should probably be rather a small change though).

@ghost
Copy link

ghost commented Jan 15, 2019

Yes, I think it would be a fine solution. This is what websocket crate does.

@daniel-abramov
Copy link
Member

For the hyper example (original question) I think you can refer to the already mentioned: https://github.com/krzysztofwos/hyper-websocket-upgrade

Would it be sufficient?

As for the possibility to get close errors, it's now merged to master (see #53), so you can use it already. We'll may also release a new version of tungstenite-rs and tokio-tungstenite.

@jbg
Copy link

jbg commented Jan 7, 2022

https://github.com/krzysztofwos/hyper-websocket-upgrade is a 404 error now, is there any newer example for hyper & tokio-tungstenite?

@holly-hacker
Copy link

For those still looking for an alternative, hyper-tungstenite seems like a way to do this.

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

No branches or pull requests

4 participants