D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
td-agent
/
embedded
/
lib
/
ruby
/
gems
/
2.1.0
/
gems
/
cool.io-1.5.1
/
examples
/
Filename :
dslified_echo_client.rb
back
Copy
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'rubygems' require 'cool.io' ADDR = '127.0.0.1' PORT = 4321 cool.io.connect ADDR, PORT do on_connect do puts "Connected to #{remote_host}:#{remote_port}" write "bounce this back to me" end on_close do puts "Disconnected from #{remote_host}:#{remote_port}" end on_read do |data| puts "Got: #{data}" close end on_resolve_failed do puts "Error: Couldn't resolve #{remote_host}" end on_connect_failed do puts "Error: Connection refused to #{remote_host}:#{remote_port}" end end puts "Echo client connecting to #{ADDR}:#{PORT}..." cool.io.run