473,326 Members | 2,125 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,326 software developers and data experts.

ReadToEnd() Blocking

Hi,

I am writing to a network stream using the following code:

TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("192.168.2.100"), 55650);
NetworkStream stream = client.GetStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write("TEST");
writer.Flush();

Now, I am reading from the network stream using the following code:

NetworkStream netStrm = new NetworkStream(socket);
StreamReader reader = new StreamReader(netStrm);
string str = reader.ReadToEnd();

The method ReadToEnd(), is blocking the client application is
terminated. I also tried to client.Close(), but still method blocks.

Is there a way to read all data sent without terminating the client.
Can someone help me out
Thanks in Advance

Nov 17 '05 #1
3 10692
<be*********@yahoo.com> wrote:
I am writing to a network stream using the following code:

TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("192.168.2.100"), 55650);
NetworkStream stream = client.GetStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write("TEST");
writer.Flush();

Now, I am reading from the network stream using the following code:

NetworkStream netStrm = new NetworkStream(socket);
StreamReader reader = new StreamReader(netStrm);
string str = reader.ReadToEnd();

The method ReadToEnd(), is blocking the client application is
terminated. I also tried to client.Close(), but still method blocks.

Is there a way to read all data sent without terminating the client.


No - there's no real sense of "all data" until the stream has been
closed, because the server could always have sent some more since you
thought you'd got it all.

If you're able to design the protocol yourself, it's a *really* good
idea to state how much data you're going to send before you send it
wherever there's a variable amount.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
be*********@yahoo.com wrote:
Hi,

I am writing to a network stream using the following code:

TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("192.168.2.100"), 55650);
NetworkStream stream = client.GetStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write("TEST");
writer.Flush();

Now, I am reading from the network stream using the following code:

NetworkStream netStrm = new NetworkStream(socket);
StreamReader reader = new StreamReader(netStrm);
string str = reader.ReadToEnd();

The method ReadToEnd(), is blocking the client application is
terminated. I also tried to client.Close(), but still method blocks.

Is there a way to read all data sent without terminating the client.
Can someone help me out
Thanks in Advance


Have you looked into the Asynchronous methods such as BeginRead,
BeginWrite etc...? Thes operations are executed on a background thread
and shouldn't block the apps main thread.

--
Rob Schieber
Nov 17 '05 #3
client.shutdown(send) (or shutdown(both) ) from the client will unblock
server blocking read and read will return 0. Even if you "packetize" your
stream with pre-pended len bytes, you most likely need to do this anyway to
signal to the server that your not sending any more messages.
--
William Stacey [MVP]

<be*********@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi,

I am writing to a network stream using the following code:

TcpClient client = new TcpClient();
client.Connect(IPAddress.Parse("192.168.2.100"), 55650);
NetworkStream stream = client.GetStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write("TEST");
writer.Flush();

Now, I am reading from the network stream using the following code:

NetworkStream netStrm = new NetworkStream(socket);
StreamReader reader = new StreamReader(netStrm);
string str = reader.ReadToEnd();

The method ReadToEnd(), is blocking the client application is
terminated. I also tried to client.Close(), but still method blocks.

Is there a way to read all data sent without terminating the client.
Can someone help me out
Thanks in Advance

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hal | last post by:
I am experiencing blocking problems on SQL Server 2000, SP3a. I have read the posts and set up a job SQL agent to report on these occurences I save the results to a table before executing an sp to...
3
by: David Sworder | last post by:
This message was already cross-posted to C# and ADO.NET, but I forgot to post to this "general" group... sorry about that. It just occured to me after my first post that the "general" group readers...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
7
by: Michi Henning | last post by:
Hi, I'm using a non-blocking connect to connect to a server. Works fine -- the server gets and accepts the connection. However, once the connection is established, I cannot retrieve either the...
2
by: Nad | last post by:
Hello All, I have been trying to get some sort of documantion on how StreamReader.ReadToEnd() finds out if the stream has ended and if anyone can read the following lines and tell me how to...
3
by: loosecannon_1 | last post by:
I get a 90-120 second blocking when send 15 or so simultaneous queries to SQL Server 2000 that query a view made up of two joined tables. After each query is blocking for the same amount of time...
4
by: Chris S. | last post by:
I'm curious - does StreamReader.ReadToEnd() handle chunk loading of data or does it block until the whole stream is loaded? I've been use to handling the buffer myself but I'm thinking maybe this...
1
by: opi | last post by:
My blocking TCP server hangs in the Accept method when the client software sometimes gets an error. Are there any ways to stop this blocking in the Accept method so I dont have to restart the...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.