ruby - Websocket connection closes without opening on Shotgun server -
i have sinatra app uses websockets. app works when run ruby app.rb
, doesn't when i'm trying run shotgun app.rb
.
this in sending_out.erb:
<script> $(document).ready(function(){ connection = new websocket('ws://' + window.location.host + window.location.pathname); connection.onopen = function(){ $("#msgs").append('connection opened'+"<br>") }; connection.onmessage = function(e){ $("#msgs").append(e.data+"<br>"); }; connection.onclose = function() { $("#msgs").append('connection closes view'+"<br>"); }; $("form").submit(function(){ connection.send( $("input").val() ); }); }); </script>
and in app.rb:
require 'sinatra-websocket' set :sockets, [] '/sending_out' request.websocket |connection| connection.onopen connection.send("hello world!") settings.sockets << connection connection.send("opened") connection.send("went") end connection.onmessage |msg| em.next_tick { settings.sockets.each{|s| s.send(msg) } } end connection.onclose warn("websocket closed") settings.sockets.delete(ws) end end end
it must show
connection opened hello world! opened went
when go page. shows
connection closes view
with shotgun.
and in console says websocket connection 'ws://127.0.0.1:9393/sending_out' failed: error during websocket handshake: unexpected response code: 500.
is there issue running websockets shotgun?
the main feature of shotgun automatically reloads whole code every request , think problem facing.
shotgun should used development.
for production purposes have plenty of other options available:
puma rainbows unicorn thin otherscomparison of ruby servers can found on https://www.digitalocean.com/community/tutorials/a-comparison-of-rack-web-servers-for-ruby-web-applications
ruby websocket sinatra shotgun
No comments:
Post a Comment