Xiangrong Fang wrote:

> 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.

 > [...]
> 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  <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