From: Eric Hu Date: 2011-07-20T06:05:51+09:00 Subject: Re: Code works in IRB but not when saved and run (NET/TOC) --20cf30051046d69b7b04a8727ab0 Content-Type: text/plain; charset=ISO-8859-1 So I ran your code. I notice that client.connect returns a separate thread, so creating your own event/thread with EM shouldn't be needed. take a look at the documentation: http://net-toc.rubyforge.org/doc/classes/Net/TOC/Client.html#M000012 wait(limit=nil) Waits for the event-handling thread for limit seconds, or indefinitely if no argument is given. Use this to prevent your program from exiting prematurely... I haven't been able to get a ruby script to connect, and doing it in IRB works for me, too. I think using client.wait (instead of sleep) is going in the right direction. I did a "puts client.buddy_list" in the client, which reported back my buddy list. However, doing this in the script printed out an empty line, so it looks like the connection isn't completing. You may want to try playing with this some more--hope this helps On Tue, Jul 19, 2011 at 1:34 PM, Opviel Krevt wrote: > No errors. The rb file completes-- but the account never signs on and no > message is sent. RUBY_VERSION yields 1.8.7 for both the rb file and irb. > > Using eventmachine, would it look something like this? > > EventMachine::run do > > #Define TOC Connection > client = Net::TOC.new(username, password) > > #Connect > client.connect > > #Grab object associated with buddy's screenname > friend = client.buddy_list.buddy_named(screenname) > > #Sends the IM > friend.send_im(message) > > end > > -- > Posted via http://www.ruby-forum.com/. > > --20cf30051046d69b7b04a8727ab0--