Sha256: 239707938c3e63853d0c8ec000563eaa4a225267aa745d6e83dd2c23ac4bbfb3

Contents?: true

Size: 547 Bytes

Versions: 1

Compression:

Stored size: 547 Bytes

Contents

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

require 'rubygems'
require 'cool.io'

ADDR = '127.0.0.1'
PORT = 4321

class EchoServerConnection < Coolio::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

event_loop = Coolio::Loop.default
Coolio::TCPServer.new(ADDR, PORT, EchoServerConnection).attach(event_loop)

puts "Echo server listening on #{ADDR}:#{PORT}"
event_loop.run

Version data entries

1 entries across 1 versions & 1 rubygems

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