Concurrency – Sinatra websocket Celluloid ID

Do any of you know how to run a quick code example of a Sinatra application running on celluloid: IO and use websocket?

I know the existence of celloloid's scroll ("scroll is a fast, non blocking event web server built on celloid: IO"... And directly supports WebSockets), but I still want to continue to use Sinatra because I like it. I'm used to it. I'd rather not rewrite a lot of code

I hope you can help

Solution

Celluloid:: IO has an event http / websocket server named reel( http://github.com/celluloid/reel ), it's the best setting you want, but it's very new except thin and rainbow This goes beyond Sinatra and must involve the rack itself So far, it has targeted some HTTP servers, and each "rack handler" approaches WebSockets in its own way Now it's a little standardized, but it will become permanent in rack 2.0 I guess this temporary approach will continue, but it is more mature in 2.0 than it is now

This is about to be released to the main branch of the reel, but now it is a branch of the fork of a halgorium, here:

https://github.com/halorgium/reel/tree/hijacked-websocket

This issue is ongoing:

https://github.com/celluloid/reel/issues/42

The implementation of this function involves the interaction of new functions and slightly temporary functions related to the hijacking API in rack under Sinatra It's quite complicated, but once you get it in suspense, it's cool The complete information in this regard is here:

According to @rhk, there is no formal support for WebSockets to hijack Sinatra through rack. Except for middleware, there is no plan So it will always be your choice, based on your server and implementation style

The way I handled it was with reel, but puma( http://puma.io )Also very good Any with hijack_ All HTTP servers with IO function will run The way I do this is explained in the link below It uses websocket protocol ruby to actually handle the interaction with the client. On the client, I use portal JS, rather than pure HTML5 methods I believe it will be much better

Portal. js: https://github.com/flowersinthesand/portal

websocket-protocol-ruby: https://github.com/faye/websocket-protocol-ruby

It all depends on this work, as described in the rack API thread in GitHub:

env['rack.hijack'].call
@env = env
@io = env['rack.hijack_io']

There are two ways to use hijack_ IO, but as I said, it's very organic There is not much Sinatra code because it is not really Sinatra Again, as I mentioned, it doesn't even have a real plan to become seamless This will be a Sinatra / contrib thing or some other middleware So here's my way in which I use hijack_ IO case, as a rough sketch

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>