erithmetic / socket.io-ruby

Ruby/Cramp/Eventmachine implementation of Socket.io. Status: abandonware
MIT License
53 stars 10 forks source link

Emit events to client #1

Open ngshvanam52 opened 12 years ago

ngshvanam52 commented 12 years ago

Server to client emitting the events is not happening. Can please provide the necessary details. My email Id is ngshvanam52@gmail.com Thank you.

codeholic commented 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>
erithmetic commented 12 years ago

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.

codeholic commented 12 years ago

Thank you for your feedback!

ghost commented 12 years ago

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!

codeholic commented 12 years ago

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.