Created
September 11, 2009 04:52
-
-
Save zlu/185081 to your computer and use it in GitHub Desktop.
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
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 | |
} |
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
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