Sha256: 94c5f93bf8c5c0e5af7bdbddb2c73530c8c67185fa93120bd233438e448a7754

Contents?: true

Size: 732 Bytes

Versions: 14

Compression:

Stored size: 732 Bytes

Contents

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

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

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

  puts "start websocket server - port:#{PORT}"

  WebSocket::EventMachine::Server.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

14 entries across 14 versions & 1 rubygems

Version Path
websocket-client-simple-0.9.0 sample/echo_server.rb
websocket-client-simple-0.8.0 sample/echo_server.rb
websocket-client-simple-0.7.0 sample/echo_server.rb
websocket-client-simple-0.6.1 sample/echo_server.rb
websocket-client-simple-0.6.0 sample/echo_server.rb
websocket-client-simple-0.5.1 sample/echo_server.rb
websocket-client-simple-0.5.0 sample/echo_server.rb
websocket-client-simple-0.4.0 sample/echo_server.rb
websocket-client-simple-0.3.1 sample/echo_server.rb
websocket-client-simple-0.3.0 sample/echo_server.rb
websocket-client-simple-0.2.5 sample/echo_server.rb
websocket-client-simple-0.2.4 sample/echo_server.rb
websocket-client-simple-0.2.3 sample/echo_server.rb
websocket-client-simple-0.2.2 sample/echo_server.rb