472,782 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 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 4313
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...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.