Sha256: 959a86458adc3aed98558b7961d749759c1ed0a2ef488000891607dc13938c73

Contents?: true

Size: 528 Bytes

Versions: 1

Compression:

Stored size: 528 Bytes

Contents

# WebSocket echo server

require 'rubygems'
require 'rev/websocket'

class EchoConnection < Rev::WebSocket
	def on_open
		puts "WebSocket opened"
		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 = Rev::WebSocketServer.new(host, port, EchoConnection)
server.attach(Rev::Loop.default)

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

Rev::Loop.default.run

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rev-websocket-0.1.2 examples/echo.rb