Open ngshvanam52 opened 12 years ago
I experience the same problem. I tried the following code. The block that invokes send_message is executed, but the message is not being sent. What am I probably doing wrong?
require 'eventmachine-tail'
require 'json'
class TailAction < Cramp::Action
include SocketIo::Websocket
on_start :subscribe
on_finish :unsubscribe
@@channel = EventMachine::Channel.new
@@filetail = EventMachine::file_tail('/tmp/ponytail') do |filetail, line|
@@channel.push line
end
def subscribe
@sid = @@channel.subscribe do |m|
send_message(data: { message: m }.to_json)
end
end
def unsubscribe
@@channel.unsubscribe(@sid) if @sid
end
end
<html>
<head>
<title>Ponytail</title>
<script type="text/javascript" src="javascripts/socket.io.min.js"></script>
<script>
var socket = io.connect('/socket.io');
socket.on('message', function(message) {
alert(message);
});
</script>
</head>
<body>
</body>
</html>
I've abandoned this project for two reasons: 1.) I'm not longer working on the problem this tool attempted to solve, and 2.) Cramp has been superseded by Celluloid/Lattice https://github.com/celluloid/lattice
If I find myself needing a Ruby socket-io implementation, I'd focus on a lattice-based service.
I'll accept pull requests, but I have no plans of maintaining this.
Thank you for your feedback!
I actually happen to be working on an app right now where this library would be perfect (Socket.IO without dealing with JS!).
I noticed you mentioned Lattice, but as far as I can tell, that is completely unfinished - there is no real code in the lib folder, besides a script that sets a VERSION constant. Am I missing something?
Besides that, do you have any other recommendations on libraries that may be useful for building a WebSocket application?
Thanks in advance!
I decided not to use WebSockets, after all. SSE (with long polling fallback for IE) seemed to me the way to go. Cramp supports both out of box.
Server to client emitting the events is not happening. Can please provide the necessary details. My email Id is ngshvanam52@gmail.com Thank you.