Networkstream Class and POP3 Protocol Problem

  • Thread starter Thread starter Darcy Ryan
  • Start date Start date
D

Darcy Ryan

Greetings,

I am having a problem trying to use the TcpClient and
NetworkStream classes to connect to a POP3 server. My
(simplified test) VB.NET code is as follows:

Dim tcpclient As New TcpClient
tcpclient.Connect("<server name>", 110)

Dim ns As NetworkStream = tcpclient.GetStream

Dim Rxbytes(tcpclient.ReceiveBufferSize) As Byte
ns.Read(Rxbytes, 0, CInt(tcpclient.ReceiveBufferSize))

Dim Txbytes As Byte() = Encoding.ASCII.GetBytes("USER
<name>\r\n")

ns.Write(Txbytes, 0, Txbytes.Length)

ns.Read(Rxbytes, 0, CInt(tcpclient.ReceiveBufferSize))

...

The code above will connect to the POP3 server and read
the "+OK ..." response for an active connection. The write
command executes ok, but the program hangs on the Read
command (as if the server has not recieved a valid USER
command). I have added a check for ns.DataAvailable prior
to the read, which returns no data available. I think that
I am missing something obvious in writing the USER command
(possibly with the CRLF).

I have verified my command strings by connecting to my
server using telnet, I have checked the samples on MSDN
and Google, and I am now into the 'banging head on
keyboard' stage.

Any advice?

Thanks,
Darcy
 
I have verified my command strings by connecting to my
server using telnet, I have checked the samples on MSDN
and Google, and I am now into the 'banging head on
keyboard' stage.

Any advice?

Perhaps you need to send a NULL terminated string? "\0" I know that
sometimes that is what is expected. Just a guess.

-akshay
 
I tried that both after and in place of the CRLF (\r\n)
characters (spec'd by the POP3 protocol) with no luck.
Thanks for the suggestion though, Akshay, I hadn't thought
of that.

Darcy
 
VB does not use escape sequences such as '\r\n'. Try:

Dim Txbytes As Byte() = Encoding.ASCII.GetBytes("USER <name>" &
Environment.NewLine)
 
Back
Top