469,578 Members | 1,914 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

StreamReader question

Hi, I have a simple little program that I'm going to use to access our SMTP
server. The below code works perfectly fine, but my question is if I were
to try to execute the last line (info=streamReader.ReadLine) another time,
the program hangs. Most likely since the SMTP server has no other responses
to post. Is there a way to make the streamreader time out if there is no
other info?

BTW, the only code not posted is ConnectSocket...it just resolves the DNS
and creates the socket..I lifted that from MSDN.....

Dim soc As Socket = ConnectSocket("10.0.100.11", 25)

If soc Is Nothing Then MsgBox("Connection Failed")

Dim info As String
Dim NetworkStream As New NetworkStream(soc)
Dim streamReader As StreamReader = New StreamReader(NetworkStream)
Dim streamWriter As StreamWriter = New StreamWriter(NetworkStream)
streamWriter.AutoFlush = True

'Get the initial command from the host
info = streamReader.ReadLine

'say HELO
streamWriter.WriteLine("HELO")
info = streamReader.ReadLine
info = streamReader.ReadLine ' would like to run again or in a loop to
clear out any buffered info.
Nov 20 '05 #1
1 4197
In article <#$**************@TK2MSFTNGP09.phx.gbl>, Rob T wrote:
Hi, I have a simple little program that I'm going to use to access our SMTP
server. The below code works perfectly fine, but my question is if I were
to try to execute the last line (info=streamReader.ReadLine) another time,
the program hangs. Most likely since the SMTP server has no other responses
to post. Is there a way to make the streamreader time out if there is no
other info?

BTW, the only code not posted is ConnectSocket...it just resolves the DNS
and creates the socket..I lifted that from MSDN.....

Dim soc As Socket = ConnectSocket("10.0.100.11", 25)

If soc Is Nothing Then MsgBox("Connection Failed")

Dim info As String
Dim NetworkStream As New NetworkStream(soc)
Dim streamReader As StreamReader = New StreamReader(NetworkStream)
Dim streamWriter As StreamWriter = New StreamWriter(NetworkStream)
streamWriter.AutoFlush = True

'Get the initial command from the host
info = streamReader.ReadLine

'say HELO
streamWriter.WriteLine("HELO")
info = streamReader.ReadLine
info = streamReader.ReadLine ' would like to run again or in a loop to
clear out any buffered info.


Well, you can set the send and recv timout values on the socket by using
the SetSocketOption method... But, that isn't really the best way to do
this. The smtp protocol terminates all messages with a cr/lf. In this
case above there will be no buffered data after the first readline since
readline will not return until it recieves the CR/LF.

--
Tom Shelton [MVP]
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by andrewcw | last post: by
1 post views Thread by Tarren | last post: by
9 posts views Thread by Matt Bailey | last post: by
4 posts views Thread by somequestion | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.