Skip to content

Instantly share code, notes, and snippets.

@hinrik
Forked from tarcieri/echo_server.rb
Created September 29, 2011 14:40
Show Gist options
  • Save hinrik/1250865 to your computer and use it in GitHub Desktop.
Save hinrik/1250865 to your computer and use it in GitHub Desktop.
Cool.io echo server using the fancy new DSL
require 'rubygems'
require 'cool.io'
ADDR = 'localhost'
PORT = 4321
cool.io.server ADDR, PORT do
on_connect do
puts "#{remote_addr}:#{remote_port} connected"
end
on_close do
puts "#{remote_addr}:#{remote_port} disconnected"
end
on_read do |data|
write data
end
end
puts "Echo server listening on #{ADDR}:#{PORT}"
cool.io.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment