Networkstream Class and POP3 Protocol Problem

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
 
A

A

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
 
D

Darcy Ryan

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
 
S

Stephen Martin

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

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

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

Similar Threads

TcpClient and images 3
NNTP Client 4
TCP Transfer issues 3
a simple client example 3
TCP/IP 3
Testing client server application from single computer 3
Networkstream Returning Null Value 2
How to debug this? 10

Top