For a high-performance websocket server, ideally I want to reorient Iron to listen websockets instead of http(s).
Is it possible to use rust-websocket with iron, or does it not make sense to use both together?
If it is possible, how can I realize it?
Since your goal is to create a high-performance websocket server, then starting with an HTTP server, like Iron, probably does not make sense. (Iron is based on Hyper, which advertises itself as "a fast and correct HTTP implementation"). I would recommend looking at tokio which was designed as "an asynchronous, event driven platform" and is used by Hyper and Iron.
WebSockets require a different protocol that creates a two-way interactive communication session. From Mozilla docs:
you can send messages to a server and receive event-driven responses without having to poll the server for a reply.
So, if you don't need HTTP, then starting with a server that is focused on request/response is likely to introduce more complexity than benefit. While iron websocket issue is still open, recent comment notes:
Personally I think it's pretty difficult to fit websocket into Iron's request-middleware-response model. I haven't seen elegant abstraction in other languages for this.
If you really want to explore using WebSockets with Iron, you would need to extend hyper to support WebSockets (good discussion here) and then access lower-level hyper connection (explained in iron issue #478). After establishing the connection, a WebSocket library would be useful (though rust-websocket appears to be no longer maintained).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With