Sha256: d42b3959228aa3faaa2f3f5fe565407839e1dbb12ee18e2d870853032265d63c

Contents?: true

Size: 598 Bytes

Versions: 1

Compression:

Stored size: 598 Bytes

Contents

# WebSocket echo server

require 'rubygems'
require 'cool.io-websocket'

class EchoConnection < Cool.io::WebSocket
	def on_open
		puts "WebSocket opened from '#{peeraddr[2]}': request=#{request.inspect}"
		send_message("server: Hello, world!")
	end

	def on_message(data)
		puts "WebSocket data received: '#{data}'"
		send_message(data)
	end

	def on_close
		puts "WebSocket closed"
	end
end

host = '0.0.0.0'
port = ARGV[0] || 8081

server = Cool.io::WebSocketServer.new(host, port, EchoConnection)
server.attach(Cool.io::Loop.default)

puts "start on #{host}:#{port}"

Cool.io::Loop.default.run

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cool.io-websocket-0.1.4 examples/echo.rb