Sha256: 129c533cf9803952627a1fab0f659b349e1892e84d4660143043c1fc0805e1da

Contents?: true

Size: 696 Bytes

Versions: 12

Compression:

Stored size: 696 Bytes

Contents

#!/usr/bin/env ruby
require 'eventmachine'
require 'em-websocket'

PORT = (ARGV.shift || 8080).to_i

EM::run do
  @channel = EM::Channel.new

  puts "start websocket server - port:#{PORT}"
  EM::WebSocket.start(:host => "0.0.0.0", :port => PORT) do |ws|
    ws.onopen do
      sid = @channel.subscribe do |mes|
        ws.send mes
      end
      puts "<#{sid}> connect"

      @channel.push "hello new client <#{sid}>"

      ws.onmessage do |msg|
        puts "<#{sid}> #{msg}"
        @channel.push "<#{sid}> #{msg}"
      end

      ws.onclose do
        puts "<#{sid}> disconnected"
        @channel.unsubscribe sid
        @channel.push "<#{sid}> disconnected"
      end
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
websocket-client-simple-0.2.1 sample/echo_server.rb
websocket-client-simple-0.2.0 sample/echo_server.rb
websocket-client-simple-0.1.0 sample/echo_server.rb
websocket-client-simple-0.0.9 sample/echo_server.rb
websocket-client-simple-0.0.8 sample/echo_server.rb
websocket-client-simple-0.0.7 sample/echo_server.rb
websocket-client-simple-0.0.6 sample/echo_server.rb
websocket-client-simple-0.0.5 sample/echo_server.rb
websocket-client-simple-0.0.4 sample/echo_server.rb
websocket-client-simple-0.0.3 sample/echo_server.rb
websocket-client-simple-0.0.2 sample/echo_server.rb
websocket-client-simple-0.0.1 sample/echo_server.rb