Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using rust-websocket with Iron

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?

like image 201
Lodin Avatar asked Jun 18 '15 06:06

Lodin


1 Answers

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).

like image 96
Ultrasaurus Avatar answered Nov 09 '22 17:11

Ultrasaurus