Ask a Question related to Ruby, Design and Development.
-
Xiangrong Fang #1
socket emergency
Hi,
I had a problem when using Winsock in ruby. I tried various ways, but to
no avail. The situation is that I need to write a simple POP3 client
that pool the pop server. This is normally ok. But currently the PC
installed a version or Norman Virus Control which controls the POP3 port
(it is a proxy).
There is something strange with NVC. The symptom is that if I use my
email client to connect to it, that's fine. If I use windows Telnet, I
only get the "+OK POP3 Server Ready" prompt. After I enter "USER xxx",
or even "QUIT", it does NOT reply anything, just hang there.
I tried using the ruby Socket class and TCPSocket class the result is
same. i.e., it will hang when I use the "recv()" method. Please refer to
the following sample code:
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> t = TCPSocket.new('127.0.0.1', 110)
=> #<TCPSocket:0x2aa0230>
irb(main):006:0> t.recv(100)
=> "+OK POP3 Server Ready\r\n"
irb(main):007:0> t.send('USER xrfang@172.18.2.1\r\n', 0)
=> 26
irb(main):008:0> t.recv(100)
^CTerminate batch job (Y/N)? ^C
The irb is frozen and I pressed ^C.
Another piece of code:
irb(main):003:0> t = TCPSocket.new('127.0.0.1', 110)
=> #<TCPSocket:0x2a94098>
irb(main):005:0> t.readline
=> "+OK POP3 Server Ready\r\n"
irb(main):006:0> t.puts('USER xrfang@172.18.2.1')
=> nil
irb(main):007:0> t.readline
=> "+OK\r\n"
irb(main):008:0> t.puts('PASS xrfang')
Errno::EINVAL: Invalid argument
from (irb):8:in `write'
from (irb):8:in `puts'
from (irb):8
irb(main):009:0>
I don't know why the first "puts" is ok, while the second generated
Errno::EINVAL exception.
I also tried using Socket, not TCPSocket, but the result is similar.
Thank you very much for any advices.
Shannon
--
Xiangrong Fang <xrfang@hotmail.com>
Xiangrong Fang Guest
-
HELP! Emergency! Something farked up bad! :-(
ACK! Help! Help! Help! I've been working on a project for 2 weeks. I was wrapping it up for delivery tomorrow. I saved it, then tried reloading... -
Coverting RGB to CMYK? emergency!
Is it possible to convert a photo from rgb to cmyk in PS Elements? This is an emergency! -
Socket.accept problem via Socket.for_fd($stdin.fileno)
Hi, I am experiencing a rather infuriating problem with Socket.accept on Windows XP. The problem exists when I try to create a Socket from... -
uploading $_FILES EMERGENCY HELP!!!!!!!!
"Phil Powell" <soazine@erols.com> wrote in message news:5GR%a.20889$3M4.16826@lakeread04... past 80 80 86 '</font></font><p>'; WARNINGS -
Distinguishing between socket buffer full & socket disconnected
I am using the IO::Select method can_write() to flow control the writing of a large amount of data to a socket, where the writer may well run ahead... -
ts #2
Re: socket emergency
>>>>> "X" == Xiangrong Fang <xrfang@hotmail.com> writes:
X> irb(main):007:0> t.send('USER xrfang@172.18.2.1\r\n', 0)
X> => 26
Be carefull with '' and \r \n
svg% ruby
p 'aa\r\n'.size
p "aa\r\n".size
^D
6
4
svg%
try to use
t.send("USER xrfang@172.18.2.1\r\n", 0)
Guy Decoux
ts Guest
-
Shannon Fang #3
Re: socket emergency
Hi,
I'm sorry about the mistake, this is a typo. Please refer to the following
code:
irb(main):018:0> t = TCPSocket.new('127.0.0.1', 110)
=> #<TCPSocket:0x2b28320>
irb(main):019:0> t.readline
=> "+OK POP3 Server Ready\r\n"
irb(main):020:0> t.send("USER xrfang@172.18.2.1\n", 0)
=> 23
irb(main):021:0> t.readline
=> "+OK\r\n"
irb(main):022:0> t.send("PASS xrfang\n", 0)
=> 19
irb(main):023:0> t.readline
=> "+OK\r\n"
irb(main):024:0> t.send("STAT\n", 0)
=> 5
irb(main):025:0> t.readline
=> "+OK 5 10631\r\n"
irb(main):026:0> t.send("RETR 1", 0)
=> 6
irb(main):027:0> t.readline
After the final readline, it hang up again. I don't know the exact
difference between t.readline and t.recv, but they both hang.
Thanks,
Shannon
__________________________________________________ _______________>From: ts <decoux@moulon.inra.fr>
>Reply-To: [email]ruby-talk@ruby-lang.org[/email]
>To: [email]ruby-talk@ruby-lang.org[/email] (ruby-talk ML)
>CC: [email]ruby-talk@ruby-lang.org[/email]
>Subject: Re: socket emergency
>Date: Wed, 20 Aug 2003 22:18:20 +0900
>>> >>>>> "X" == Xiangrong Fang <xrfang@hotmail.com> writes:
>X> irb(main):007:0> t.send('USER xrfang@172.18.2.1\r\n', 0)
>X> => 26
>
> Be carefull with '' and \r \n
>
>svg% ruby
>p 'aa\r\n'.size
>p "aa\r\n".size
>^D
>6
>4
>svg%
>
> try to use
>
>
> t.send("USER xrfang@172.18.2.1\r\n", 0)
>
>
>Guy Decoux
>
>
Tired of 56k? Get a FREE BT Broadband connection
[url]http://www.msn.co.uk/specials/btbroadband[/url]
Shannon Fang Guest
-
Philipp Ott #4
Re: socket emergency
Xiangrong Fang wrote:
Strange this with the telnet, this should work.> Hi,
>
> I had a problem when using Winsock in ruby. I tried various ways, but to
> no avail. The situation is that I need to write a simple POP3 client
> [...]
> same. i.e., it will hang when I use the "recv()" method. Please refer to
> [...]
> irb(main):007:0> t.send('USER xrfang@172.18.2.1\r\n', 0)
I think your code didnt work because of the \r and \n literals in the
msg exchange. So you need to use double-quotes " for the string or
stay with .puts but without the CR LF.
irb(main):001:0> require 'socket'> [...]
> Thank you very much for any advices.
=> true
irb(main):002:0> t = TCPsocket.new('mail.avalon.at',110)
=> #<TCPSocket:0x400d1d98>
irb(main):003:0> t.readline
=> "+OK ready <13032.1061385513@ns4.avalon.at>\r\n"
irb(main):004:0> t.puts('USER philipp')
=> nil
irb(main):005:0> t.readline
=> "+OK Password required for philipp.\r\n"
irb(main):006:0> t.puts('PASS test123')
=> nil
irb(main):007:0> t.readline
=> "-ERR [AUTH] Password supplied for \"philipp\" is incorrect.\r\n"
irb(main):008:0> t.puts('quit')
=> nil
irb(main):009:0> t.readline
=> "+OK Pop server at ns4.avalon.at signing off.\r\n"
hope it helps
Philipp Ott
Philipp Ott Guest
-
Michael Campbell #5
Re: socket emergency
> > Hi,
>> >
> > I had a problem when using Winsock in ruby. I tried various ways, but to
> > no avail. The situation is that I need to write a simple POP3 client
> > [...]
> > same. i.e., it will hang when I use the "recv()" method. Please refer to
> > [...]
> > irb(main):007:0> t.send('USER xrfang@172.18.2.1\r\n', 0)
> Strange this with the telnet, this should work.
>
> I think your code didnt work because of the \r and \n literals in the
> msg exchange. So you need to use double-quotes " for the string or
> stay with .puts but without the CR LF.
I'm wondering why the net/pop.rb library isn't sufficient?
Michael Campbell Guest
-
Shannon Fang #6
Re: socket emergency
I am _very_ sorry as this is a typo again. Please see following code:
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> t= TCPSocket.new('127.0.0.1', 110)
=> #<TCPSocket:0x2aa0908>
irb(main):003:0> t.gets
=> "+OK POP3 Server Ready\r\n"
irb(main):004:0> t.send("USER xrfang@172.18.2.1\n", 0)
=> 23
irb(main):005:0> t.gets
=> "+OK\r\n"
irb(main):006:0> t.send("PASS xrfang\n", 0)
=> 12
irb(main):007:0> t.gets
=> "+OK\r\n"
irb(main):008:0> t.send("RETR 4\n", 0)
=> 7
irb(main):009:0> t.gets
=> "+OK\r\n"
irb(main):010:0> t.gets
It hangs here.
Sincerely,
Shannon
__________________________________________________ _______________>From: ts <decoux@moulon.inra.fr>
>Reply-To: [email]ruby-talk@ruby-lang.org[/email]
>To: [email]ruby-talk@ruby-lang.org[/email] (ruby-talk ML)
>CC: [email]ruby-talk@ruby-lang.org[/email]
>Subject: Re: socket emergency
>Date: Wed, 20 Aug 2003 22:39:32 +0900
>>> >>>>> "S" == Shannon Fang <xrfang@hotmail.com> writes:
>S> irb(main):026:0> t.send("RETR 1", 0)
> ^^^^^^
>
> You have forgotten \n
>
>S> => 6
>
>
>Guy Decoux
>
Stay in touch with absent friends - get MSN Messenger
[url]http://www.msn.co.uk/messenger[/url]
Shannon Fang Guest
-
Shannon Fang #7
Re: socket emergency
Hi Guy and all Rubyists,
Thank you very much for all the help. For me, it is not very convenient to
use net/pop in this client application. However I also tried that one. The
result is failure. Please refer to the following code:
irb(main):001:0> require 'net/pop'
=> true
irb(main):002:0> Net::POP3.start('127.0.0.1', 110,
'xrfang@172.18.2.1','xrfang') { |pop|
irb(main):003:1* if pop.mails.empty?
irb(main):004:2> puts 'no mail.'
irb(main):005:2> else
irb(main):006:2* i=0
irb(main):007:2> pop.each_mail do |m|
irb(main):008:3* puts m.pop
irb(main):009:3> m.delete
irb(main):010:3> i += 1
irb(main):011:3> end
irb(main):012:2> puts "#{pop.mails.size} mails popped."
irb(main):013:2> end
irb(main):014:1> }
TimeoutError: socket read timeout (60 sec)
from c:/ruby/lib/ruby/1.6/net/protocol.rb:618:in `on_read_timeout'
from c:/ruby/lib/ruby/1.6/net/protocol.rb:612:in `rbuf_fill'
from c:/ruby/lib/ruby/1.6/net/protocol.rb:551:in `readuntil'
from c:/ruby/lib/ruby/1.6/net/protocol.rb:577:in `read_pendstr'
from c:/ruby/lib/ruby/1.6/net/pop.rb:562:in `retr'
from c:/ruby/lib/ruby/1.6/net/pop.rb:561:in `atomic'
from c:/ruby/lib/ruby/1.6/net/pop.rb:561:in `retr'
from c:/ruby/lib/ruby/1.6/net/pop.rb:481:in `pop'
from (irb):8
from (irb):7:in `each'
from c:/ruby/lib/ruby/1.6/net/pop.rb:421:in `each_mail'
from (irb):7
from (irb):2:in `start'
from c:/ruby/lib/ruby/1.6/net/protocol.rb:71:in `start'
from c:/ruby/lib/ruby/1.6/net/protocol.rb:71:in `start'
from (irb):2
irb(main):015:0>
I don't know what on earth is it doing :-((((
thanks!
Shannon
__________________________________________________ _______________>From: ts <decoux@moulon.inra.fr>
>Reply-To: [email]ruby-talk@ruby-lang.org[/email]
>To: [email]ruby-talk@ruby-lang.org[/email] (ruby-talk ML)
>CC: [email]ruby-talk@ruby-lang.org[/email]
>Subject: Re: socket emergency
>Date: Thu, 21 Aug 2003 00:03:45 +0900
>>> >>>>> "S" == Shannon Fang <xrfang@hotmail.com> writes:
>S> It hangs here.
>
> Have you tried with the module 'net/pop' to see if it do the same ?
>
>=== Enshort Code
>
>The example above is very verbose. You can enshort code by using
>some utility methods. At first, block form of Net::POP3.start can
>alternates POP3.new, POP3#start and POP3#finish.
>
> require 'net/pop'
>
> Net::POP3.start('pop.example.com', 110,
> 'YourAccount', 'YourPassword') {|pop|
> if pop.mails.empty?
> puts 'no mail.'
> else
> i = 0
> pop.each_mail do |m| # or "pop.mails.each ..."
> File.open("inbox/#{i}", 'w') {|f|
> f.write m.pop
> }
> m.delete
> i += 1
> end
> puts "#{pop.mails.size} mails popped."
> end
> }
>
>
>
>Guy Decoux
>
It's fast, it's easy and it's free. Get MSN Messenger today!
[url]http://www.msn.co.uk/messenger[/url]
Shannon Fang Guest
-
Shannon Fang #8
Re: socket emergency
Oh I forgot to mention that while you comment on this, please note that the
local POP server (Norman) is ok, because I tried several mail clients it
worked (Becky, OE, Outlook...).
Thanks!
Shannon
__________________________________________________ _______________>From: ts <decoux@moulon.inra.fr>
>Reply-To: [email]ruby-talk@ruby-lang.org[/email]
>To: [email]ruby-talk@ruby-lang.org[/email] (ruby-talk ML)
>CC: [email]ruby-talk@ruby-lang.org[/email]
>Subject: Re: socket emergency
>Date: Thu, 21 Aug 2003 00:03:45 +0900
>>> >>>>> "S" == Shannon Fang <xrfang@hotmail.com> writes:
>S> It hangs here.
>
> Have you tried with the module 'net/pop' to see if it do the same ?
>
>=== Enshort Code
>
>The example above is very verbose. You can enshort code by using
>some utility methods. At first, block form of Net::POP3.start can
>alternates POP3.new, POP3#start and POP3#finish.
>
> require 'net/pop'
>
> Net::POP3.start('pop.example.com', 110,
> 'YourAccount', 'YourPassword') {|pop|
> if pop.mails.empty?
> puts 'no mail.'
> else
> i = 0
> pop.each_mail do |m| # or "pop.mails.each ..."
> File.open("inbox/#{i}", 'w') {|f|
> f.write m.pop
> }
> m.delete
> i += 1
> end
> puts "#{pop.mails.size} mails popped."
> end
> }
>
>
>
>Guy Decoux
>
Sign-up for a FREE BT Broadband connection today!
[url]http://www.msn.co.uk/specials/btbroadband[/url]
Shannon Fang Guest



Reply With Quote

