Skip to content

Instantly share code, notes, and snippets.

@thehack
Created December 30, 2010 14:53
Show Gist options
  • Save thehack/759864 to your computer and use it in GitHub Desktop.
Save thehack/759864 to your computer and use it in GitHub Desktop.
Need Help. Trying to figure out how to build a chat application like node.js example with Rainbows! and Coolio
# config.ru
app = proc do |env|
[ 200, {'Content-Type' => 'text/html'}, "hello world" ]
end
run app
# coolio_config.rb
require 'cool.io'
Rainbows! do
use :Coolio
HOST = 'localhost'
PORT = 4321
class EchoServerConnection < Cool.io::TCPSocket
def on_connect
puts "#{remote_addr}:#{remote_port} connected"
end
def on_close
puts "#{remote_addr}:#{remote_port} disconnected"
end
def on_read(data)
write data
end
end
server = Cool.io::TCPServer.new(HOST, PORT, EchoServerConnection)
server.attach(Cool.io::Loop.default)
puts "Echo server listening on #{HOST}:#{PORT}"
Cool.io::Loop.default.run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment