StreamReader

  • Thread starter Thread starter Jon Skeet [C# MVP]
  • Start date Start date
J

Jon Skeet [C# MVP]

Lou said:
I am using the StreamReader to read data from a network pipe.
these function hang
sr.peek()
sr.readAll()
sr.read()
when there is no more data in the pipe.
sr.ReadLine works because there are CR's.

Is this because there is no null character in the pipe to signal the EOF?

You don't get a "null character" to signal an end of stream on a socket
connection - you just get a closed socket.
What do I call to see if the pipe is empty?
How do I get all the data from the pipe?

Example reads all the character then hangs when there is no more data.
nChar never returns -1, it just hangs...

You need to make the other end of the connection close it.
 
I am using the StreamReader to read data from a network pipe.
these function hang
sr.peek()
sr.readAll()
sr.read()
when there is no more data in the pipe.
sr.ReadLine works because there are CR's.

Is this because there is no null character in the pipe to signal the EOF?

What do I call to see if the pipe is empty?
How do I get all the data from the pipe?

Example reads all the character then hangs when there is no more data.
nChar never returns -1, it just hangs...
// keep reading until the buffer is empty
int nChar;

nChar=sr.Read();

while (nChar != -1)

{

nChar=sr.Read();

}


-Lou
 
Jon and Lou,

Also, some protocols have way of indicating that the response to the
last request is complete. For example, the NNTP protocol uses a period
followed by a carriage return/line feed combination to indicate that the
response is complete. You might also have to do something protocol
specific, if the protocol doesn't indicate that the connection should be
severed.

Hope this helps.
 
Hi,

I believe that is the SMTP the one that works that way.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Nicholas Paldino said:
Jon and Lou,

Also, some protocols have way of indicating that the response to the
last request is complete. For example, the NNTP protocol uses a period
followed by a carriage return/line feed combination to indicate that the
response is complete. You might also have to do something protocol
specific, if the protocol doesn't indicate that the connection should be
severed.

Hope this helps.
 
Its not a socket connection, its a network pipe and the pipe never closes?
The pipe server is from another app I don't have control over.
Maybe i should not use the stream reader and just use APi ReadFile
along with PeekNamedPipe????


Nicholas Paldino said:
Jon and Lou,

Also, some protocols have way of indicating that the response to the
last request is complete. For example, the NNTP protocol uses a period
followed by a carriage return/line feed combination to indicate that the
response is complete. You might also have to do something protocol
specific, if the protocol doesn't indicate that the connection should be
severed.

Hope this helps.
 
Lou,

The idea that Nicholas gave you is valid in this context, you can define a
sequence in your protocol to indicate the end of the data.
SMTP use this technique, you use a . followed by a return to indicate the
end of the message, something like this you should use.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Lou said:
Its not a socket connection, its a network pipe and the pipe never closes?
The pipe server is from another app I don't have control over.
Maybe i should not use the stream reader and just use APi ReadFile
along with PeekNamedPipe????


message news:[email protected]...
Jon and Lou,

Also, some protocols have way of indicating that the response to the
last request is complete. For example, the NNTP protocol uses a period
followed by a carriage return/line feed combination to indicate that the
response is complete. You might also have to do something protocol
specific, if the protocol doesn't indicate that the connection should be
severed.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jon Skeet said:
I am using the StreamReader to read data from a network pipe.
these function hang
sr.peek()
sr.readAll()
sr.read()
when there is no more data in the pipe.
sr.ReadLine works because there are CR's.

Is this because there is no null character in the pipe to signal the EOF?

You don't get a "null character" to signal an end of stream on a socket
connection - you just get a closed socket.

What do I call to see if the pipe is empty?
How do I get all the data from the pipe?

Example reads all the character then hangs when there is no more data.
nChar never returns -1, it just hangs...

You need to make the other end of the connection close it.
 
Ignacio,

Are you sure the NNTP protocol doesn't work that way? <evil grin>

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

I believe that is the SMTP the one that works that way.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

message news:[email protected]...
Jon and Lou,

Also, some protocols have way of indicating that the response to the
last request is complete. For example, the NNTP protocol uses a period
followed by a carriage return/line feed combination to indicate that the
response is complete. You might also have to do something protocol
specific, if the protocol doesn't indicate that the connection should be
severed.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Jon Skeet said:
I am using the StreamReader to read data from a network pipe.
these function hang
sr.peek()
sr.readAll()
sr.read()
when there is no more data in the pipe.
sr.ReadLine works because there are CR's.

Is this because there is no null character in the pipe to signal the EOF?

You don't get a "null character" to signal an end of stream on a socket
connection - you just get a closed socket.

What do I call to see if the pipe is empty?
How do I get all the data from the pipe?

Example reads all the character then hangs when there is no more data.
nChar never returns -1, it just hangs...

You need to make the other end of the connection close it.
 
Nicholas,

Well, now that I think it, no, I'm not sure :D

I do know that SMTP works that way ;)

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Nicholas Paldino said:
Ignacio,

Are you sure the NNTP protocol doesn't work that way? <evil grin>

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:[email protected]...
Hi,

I believe that is the SMTP the one that works that way.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

message news:[email protected]...
Jon and Lou,

Also, some protocols have way of indicating that the response to the
last request is complete. For example, the NNTP protocol uses a period
followed by a carriage return/line feed combination to indicate that the
response is complete. You might also have to do something protocol
specific, if the protocol doesn't indicate that the connection should be
severed.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am using the StreamReader to read data from a network pipe.
these function hang
sr.peek()
sr.readAll()
sr.read()
when there is no more data in the pipe.
sr.ReadLine works because there are CR's.

Is this because there is no null character in the pipe to signal the
EOF?

You don't get a "null character" to signal an end of stream on a socket
connection - you just get a closed socket.

What do I call to see if the pipe is empty?
How do I get all the data from the pipe?

Example reads all the character then hangs when there is no more data.
nChar never returns -1, it just hangs...

You need to make the other end of the connection close it.
 
my app ids the client app and I never know what the server puts is in the
pipe.


Ignacio Machin ( .NET/ C# MVP ) said:
Lou,

The idea that Nicholas gave you is valid in this context, you can define a
sequence in your protocol to indicate the end of the data.
SMTP use this technique, you use a . followed by a return to indicate the
end of the message, something like this you should use.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Lou said:
Its not a socket connection, its a network pipe and the pipe never closes?
The pipe server is from another app I don't have control over.
Maybe i should not use the stream reader and just use APi ReadFile
along with PeekNamedPipe????


message news:[email protected]...
Jon and Lou,

Also, some protocols have way of indicating that the response to the
last request is complete. For example, the NNTP protocol uses a period
followed by a carriage return/line feed combination to indicate that the
response is complete. You might also have to do something protocol
specific, if the protocol doesn't indicate that the connection should be
severed.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am using the StreamReader to read data from a network pipe.
these function hang
sr.peek()
sr.readAll()
sr.read()
when there is no more data in the pipe.
sr.ReadLine works because there are CR's.

Is this because there is no null character in the pipe to signal the
EOF?

You don't get a "null character" to signal an end of stream on a socket
connection - you just get a closed socket.

What do I call to see if the pipe is empty?
How do I get all the data from the pipe?

Example reads all the character then hangs when there is no more data.
nChar never returns -1, it just hangs...

You need to make the other end of the connection close it.
 
Back
Top