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