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