Skip to content

Instantly share code, notes, and snippets.

@zlu
Created September 11, 2009 04:52
Show Gist options
  • Save zlu/185081 to your computer and use it in GitHub Desktop.
Save zlu/185081 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'eventmachine'
module DigitCollector
def post_init
puts "-- someone connected to the echo server!"
end
def receive_data data
p ">>>you sent: #{data}"
close_connection if data =~ /quit/i
end
def unbind
puts "-- someone disconnected from the echo server!"
end
end
EventMachine::run {
EventMachine::start_server "0.0.0.0", 4567, DigitCollector
}
require 'socket'
client = TCPSocket.new('sandite.orl.voxeo.net', 4567)
active_call = true
options = { :choices => '1,2,3,4,5,6,7,8,9,0' }
answer
sleep 1
say 'Hello, and welcome to the Digit Collector'
while active_call do
result = ask 'Please enter a digit, using zero to exit.', options
if result.value == '0'
active_call = false
else
client.puts result.value
say "You entered #{result.value}."
end
end
say 'Thank you, goodbye.'
client.close
hangup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment