469,645 Members | 1,722 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,645 developers. It's quick & easy.

Networkstream Class and POP3 Protocol Problem

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
Jul 19 '05 #1
3 3197
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
Jul 19 '05 #2
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

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

-akshay
.

Jul 19 '05 #3
VB does not use escape sequences such as '\r\n'. Try:

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

"Darcy Ryan" <da*******@hotmail.com> wrote in message
news:00****************************@phx.gbl...
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

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Alexander Schumann | last post: by
3 posts views Thread by Chad Myers | last post: by
2 posts views Thread by mike b | last post: by
2 posts views Thread by Uma | last post: by
1 post views Thread by rodny.romero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.