2

I am using the em-websocket to make communication for clients (may 2 or more users).

In their introduction . https://github.com/igrigorik/em-websocket

I want to modify their simple echo server example to achieve my purpose.

but in their example , the handshake.path output always show "/" .

I cannot know where the client from .

Is there have any solution that can know the client source place and make a broadcast message to all of them ?

Sirius Wang
  • 339
  • 1
  • 5
  • 15

1 Answers1

1

I found the answer in their example.

https://github.com/igrigorik/em-websocket/blob/master/examples/multicast.rb

EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug => true) do |ws|
ws.onopen {
    sid = @channel.subscribe { |msg| ws.send msg }
    @channel.push "#{sid} connected!"
ws.onmessage { |msg|
    @channel.push "<#{sid}>: #{msg}"
}
ws.onclose {
    @channel.unsubscribe(sid)
}
}
end

But i still have problem that: How can I send message to specified clients?

(e.g.) two clients (No.1 and No.2) make their own communication.

Sirius Wang
  • 339
  • 1
  • 5
  • 15