socket emergency

X

Xiangrong Fang

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 [email protected]\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 [email protected]')
=> 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
 
P

Philipp Ott

Xiangrong said:
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 [email protected]\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.
[...]
Thank you very much for any advices.

irb(main):001:0> require 'socket'
=> true
irb(main):002:0> t = TCPsocket.new('mail.avalon.at',110)
=> #<TCPSocket:0x400d1d98>
irb(main):003:0> t.readline
=> "+OK ready <[email protected]>\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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,203
Latest member
KaliShumat

Latest Threads

Top