473,378 Members | 1,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 4343
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: andrewcw | last post by:
OK I am half way there - I can manipulate the stream without the byte issue like this - but is this the way to push the new values back into the stream & write out the stream without resorting to...
4
by: Mike | last post by:
I created a StreamReader object from a local file on my c:\ drive StreamReader srTemp = new StreamReader("C:\\myFile.txt") I then used a RegEx to strip out all the html and save what's left to...
1
by: Tarren | last post by:
Hi: Question which might have something to do with encoding? I have a text file and I use the following code to iterate through. StreamReader oStreamFile = new StreamReader(sFileName); ...
7
by: Drew Berkemeyer | last post by:
Hello, I'm using the following code to read a text file in VB.NET. Dim sr As StreamReader = File.OpenText(strFilePath) Dim input As String = sr.ReadLine() While Not input Is Nothing...
4
by: Hexman | last post by:
Code below ---- I've asked a similar question on this forum earlier. This is a slightly different situation. Previous Question ---- I'm trying to save some specific web pages to disk as...
4
by: George | last post by:
Hi, I am puzzled by the following and seeking some assistance to help me understand what happened. I have very limited encoding knowledge. Our SAP system writes out a text file which includes...
9
by: Matt Bailey | last post by:
I am writing an ASP page with a C# backend. This page uses a StreamReader to input a file and pull out a specific section of the text based on markers inside. While the code I have works, I get a...
5
by: jkristia | last post by:
StreamReader throws an exception if I attempt to open a .csv file which is also opened by Excel. I checked this list and found what I though was the solution, first open the file stream in read...
4
by: somequestion | last post by:
Question 1. i am using StreamReader Class like this... string str = string.Empty; StreamReader sr = new StreamReader(fsIn,Encoding.Default) while ((str = sr.ReadLine()) != null) { // wanna get...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.