On 8/9/06, snacktime <snacktime at gmail.com>
wrote:> Looking at your tcptest class I can''t figure out how you
instantiate
> the class, add callbacks, then make the connection. Your method that
> makes the connection (self.test) is private so it can''t be called
> outside the class either. I''m probably missing something really
> basic, but it''s eluding me..
>
> Chris
Chris, here''s an example of how to use TcpTester. It''s
actually about
as simple as can be, but very nonobvious from the code. If you''ve ever
written for Python''s Twisted, this code sample will make sense
instantly.
#---------------------------------
require ''rubygems''
require ''eventmachine''
pr = proc {
tester = EventMachine::Protocols::TcpConnectTester.test(
"www.cisco.com", 443 )
tester.callback {|t| "Connection in #{t} seconds"}
tester.errback {|t| "Connection failed in #{t} seconds"}
}
EventMachine.run { pr.call }
#---------------------------------
I''ll let you play with this while I take a few more minutes to write
another email that explains it better.