Created
December 30, 2010 14:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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