By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,594 Members | 3,680 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,594 IT Pros & Developers. It's quick & easy.

StreamReader question

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.