Using rust-websocket with iron

For a high-performance web socket server, ideally I want to redirect Iron to listening on web sockets instead of http (s).

Is it possible to use rust-websocket with iron or is there no point in using both together?

If possible, how can I implement this?

+9
websocket rust iron
source share
3 answers

It sounds like you want to replace the Hyper inside Iron with a rust-websocket. It will probably be difficult, if at all possible. The iron is highly integrated with Hyper, and the entire design is built around working through HTTP (S). If this is really what you want to do, it might be worth contacting Iron developers to learn about the possibility of replacing the communication interface, but I don’t know how likely they are to be receptive to the idea.

0
source share

I look at using both Iron and rust-websocket in the same project, and the architecture I came to includes listening to websocket on a separate port. I can mask this when deploying with Nginx in front of the proxy server back to specific ports

0
source share

Since your goal is to create a high-performance web socket server, starting with an HTTP server such as Iron may not make sense. (Iron is based on Hyper , which claims to be a "fast and proper HTTP implementation.") I would recommend taking a look at tokio , which was designed as an "event-driven asynchronous platform" and used by Hyper and Iron.

WebSockets requires a different protocol that creates a two-way interactive communication session. From the Mozilla docs :

You can send messages to the server and receive event-driven responses without requesting a response from the server.

Thus, if you do not need HTTP, then starting from a request / response-oriented server is more likely to bring more complexity than good. Although the issue of iron web sockets is still open, a recent comment notes:

Personally, I think it's pretty difficult to fit websocket into the Iron Request-Middleware-Response model. I have not seen elegant abstraction in other languages ​​for this.

If you really want to explore the use of WebSockets with Iron, you need to expand Hyper to support WebSockets (a good discussion here ), and then access a lower level hyperlink (explained in Iron Problem No. 478 ). Once connected, the WebSocket library will be useful (although rust-websocket seems to be no longer supported).

0
source share

All Articles