# Works thro irb but not on commandline

**URL:** <https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783>\
**Category:** Ruby\
**Created:** [April 24, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783 "2008-04-24T22:26:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [April 24, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783/1 "2008-04-24T22:26:00Z")

</div>

i have a strange prob. when i run this code under irb, the buddy can  
recieve the message. when i run it under the ruby commandline, the  
buddy does not recive the message. i am not sure what the difference  
is.  
any pointers is appreciated.

require ‘net/toc’  
client = Net::TOC.new(“userid”,“password”)  
client.connect  
client.wait(10)  
friend = client.buddy\_list.buddy\_named(“mybuddy1”)  
client.on\_im do | message, buddy |  
puts “#{buddy.screen\_name}: #{message}”  
end  
client.on\_error do | error |  
puts “!! #{error}”  
end

friend.send\_im(" hi how going") # not sure why this is not being  
sent.  
puts client.buddy\_list.to\_s

client.disconnect()

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [April 24, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783/2 "2008-04-24T23:00:26Z")

</div>

Junkone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> i have a strange prob. when i run this code under irb, the buddy can  
> recieve the message. when i run it under the ruby commandline, the  
> buddy does not recive the message. i am not sure what the difference  
> is.

Are there any error messages associated with it not working? Have you  
checked your ~/.irbrc to make sure there’s nothing in there that would  
be letting this work, that you don’t have in the source file you are  
trying?

Have you written any test code to show it working vs. not working?

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [April 24, 2008, 11:38pm UTC](https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783/3 "2008-04-24T23:38:38Z")

</div>

On Apr 24, 4:58 pm, Peter J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Have you written any test code to show it working vs. not working?
> 
> –  
> Peter J. [pjones at domain below]  
> pmade inc. -[http://pmade.com](http://pmade.com)

i have the aol im on my machine connected as one of the buddies  
i cut and paste the code from the aimbot.rb file and execute them line  
by line and when i hit  
friend.send\_im(" hi how going")  
i get the IM on my aol client.

when i execute the aimbot.rb the message does not popup on my aim  
client. i get no errors. nothing. beats the hell out of me.

require ‘net/toc’  
client = Net::TOC.new(“userid”,“password”)  
client.connect  
friend = client.buddy\_list.buddy\_named(“mybuddy”)  
friend.send\_im(" hi how going")  
client.disconnect()

the irb is the same code as above. no typeing. just cut and paste

E:\Documents and Settings\User1\>irb  
irb(main):001:0\> require ‘net/toc’  
=\> true  
irb(main):002:0\> client = Net::TOC.new(“userid”,“password”)  
=\> #\<Net::TOC::Client:0x2eadb64 @buddy\_list=#\<Net::TOC::BuddyList:  
0x2eada88 @buddies={}, @group\_order=[],  
onn=#\<Net::TOC::Connection:0x2eadb3c @msgseq=65919,  
@user=“trad2win”\>\>, @screen\_name=“trad2win”, @callbac  
\<Proc:0x02ebb930@e:/ruby/lib/ruby/gems/1.8/gems/net-toc-0.2/./net/  
toc.rb:436\>, :config=\>#\<Proc:0x02ebb930  
by/gems/1.8/gems/net-toc-0.2/./net/toc.rb:436\>, :update\_buddy=\>#\<Proc:  
0x02ebb584@e:/ruby/lib/ruby/gems/1.  
0.2/./net/toc.rb:437\>, :error=\>#\<Proc:0x02eb6ea8@e:/ruby/lib/ruby/gems/  
1.8/gems/net-toc-0.2/./net/toc.rb:  
uddy2=\>#\<Proc:0x02ebb584@e:/ruby/lib/ruby/gems/1.8/gems/net-toc-0.2/./  
net/toc.rb:437\>}, @password="password::TOC::Connection:0x2eadb3c  
@msgseq=65919, @user=“userid”\>\>  
irb(main):003:0\> client.connect  
=\> #\<Thread:0x2eab6d4 sleep\>  
irb(main):004:0\> friend = client.buddy\_list.buddy\_named(“mybuddy”)  
=\> #\<Net::TOC::Buddy:0x2ea8754 @screen\_name=“mybuddy”,  
@last\_signon=Thu Apr 24 15:43:28 -0400 2008,  
ble, @on\_status={}, @conn=#\<Net::TOC::Connection:0x2eadb3c  
@msgseq=65923, @user=“userid”, @sock=#\<TCPSo

> , @idle\_time=0, @warning\_level=0\>  
> irb(main):005:0\> friend.send\_im(" hi how going")  
> =\> 47  
> irb(main):006:0\> client.disconnect  
> =\> nil  
> irb(main):007:0\>

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [April 25, 2008, 12:16am UTC](https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783/4 "2008-04-25T00:16:07Z")

</div>

On Apr 24, 5:39 pm, dusty [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is net/toc a gem?
> 
> try adding
> 
> require ‘rubygems’
> 
> to the top of the file

nope. it makes no difference. i even opened the gem and added a puts  
“i am here” line and can see it sending the message. but the client is  
not flashing the mesg if it not from IRB.

strangest thing i have seen.

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [April 24, 2008, 11:40pm UTC](https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783/5 "2008-04-24T23:40:58Z")

</div>

Is net/toc a gem?

try adding

require ‘rubygems’

to the top of the file

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [April 25, 2008, 12:20am UTC](https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783/6 "2008-04-25T00:20:50Z")

</div>

Junkone [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> i have the aol im on my machine connected as one of the buddies  
> i cut and paste the code from the aimbot.rb file and execute them line  
> by line and when i hit  
> friend.send\_im(" hi how going")  
> i get the IM on my aol client.

I don’t think there’s much anyone can do for you until you narrow this  
a bit further down.

I honestly think that you should start by writing some tests. If it  
were me, I’d use some test code from the gem you are using so that  
you didn’t need to use any GUI client to confirm delivery.

I might also write a test that used tcpdump(1) to look for the packets  
leaving the interface, and assert that they are actually being sent.

I’m assuming from your connect call that this protocol is based on TCP  
and not UDP. At the very least, using tcpdump should help you  
understand where the error is, on the sending side or the receiving  
side.

Good luck.

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [April 25, 2008, 3:21am UTC](https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783/7 "2008-04-25T03:21:36Z")

</div>

On Apr 24, 8:08 pm, Ken B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > message, buddy |  
> > client.disconnect()
> 
> - Show quoted text -

ok. the sleep worked. that was smart of you.

---

<div class="post-metadata">

**Author:** ![Junkone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e274bd/32.png) [@Junkone](https://www.ruby-forum.com/u/Junkone)\
**Post date:** [April 25, 2008, 2:13am UTC](https://www.ruby-forum.com/t/works-thro-irb-but-not-on-commandline/135783/8 "2008-04-25T02:13:12Z")

</div>

On Thu, 24 Apr 2008 13:23:28 -0700, Junkone wrote:

> message, buddy |  
> client.disconnect()  
> Try sleeping for a second after sending the message, but before  
> disconnecting, and see if that fixes it. (Maybe it’s some kind of  
> asynchronous communication issue in net/toc.)

–Ken
