Answer the question
In order to leave comments, you need to log in
Can't understand the ruby websocket test case, although I have a guess, can you help?
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js'></script>
<script>
$(document).ready(function(){
function debug(str){ $("#debug").append("<p>"+str+"</p>"); };
ws = new WebSocket("ws://yourservice.com/websocket");
ws.onmessage = function(evt) { $("#msg").append("<p>"+evt.data+"</p>"); };
ws.onclose = function() { debug("socket closed"); };
ws.onopen = function() {
debug("connected...");
ws.send("hello server");
};
});
</script>
</head>
<body>
<div id="debug"></div>
<div id="msg"></div>
</body>
</html>
require 'em-websocket'
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080) do |ws|
ws.onopen { ws.send "Hello Client!"}
ws.onmessage { |msg| ws.send "Pong: #{msg}" }
ws.onclose { puts "WebSocket closed" }
end
Answer the question
In order to leave comments, you need to log in
Well, first of all, thin is single-threaded, use puma.
In general, you don't need an em. em serves one function here - support for multiple connections.
I don't know what kind of virtual host ws - protocol, yourservice.com url, websocket - path. all this can be on ws://0.0.0.0/subscribe
And by the way, rails has edgeapi.rubyonrails.org/classes/ActionController/L...
SSE browsers have been able to for a long time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question