Sha256: 639ccf26462ad195772228d6406702ea45c4034c365883cf2fbc49f5c3608e37

Contents?: true

Size: 770 Bytes

Versions: 1

Compression:

Stored size: 770 Bytes

Contents

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

require 'rubygems'
require 'cool.io'

ADDR = '127.0.0.1'
PORT = 4321

class ClientConnection < Coolio::TCPSocket
  def on_connect
    puts "#{remote_addr}:#{remote_port} connected"
    write "bounce this back to me"
  end

  def on_close
    puts "#{remote_addr}:#{remote_port} disconnected"
  end

  def on_read(data)
    print "got #{data}"
    close
  end

  def on_resolve_failed
    print "DNS resolve failed"
  end

  def on_connect_failed
    print "connect failed, meaning our connection to their port was rejected"
  end

end

event_loop = Coolio::Loop.default
client = ClientConnection.connect(ADDR, PORT)
client.attach(event_loop)
puts "Echo client connecting to #{ADDR}:#{PORT}..."
event_loop.run 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cool.io-0.9.0 examples/echo_client.rb