473,803 Members | 3,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetStrea m();
StreamWriter writer = new StreamWriter(st ream);
writer.Write("T EST");
writer.Flush();

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

NetworkStream netStrm = new NetworkStream(s ocket);
StreamReader reader = new StreamReader(ne tStrm);
string str = reader.ReadToEn d();

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 10760
<be*********@ya hoo.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.GetStrea m();
StreamWriter writer = new StreamWriter(st ream);
writer.Write("T EST");
writer.Flush();

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

NetworkStream netStrm = new NetworkStream(s ocket);
StreamReader reader = new StreamReader(ne tStrm);
string str = reader.ReadToEn d();

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.co m>
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*********@yah oo.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.GetStrea m();
StreamWriter writer = new StreamWriter(st ream);
writer.Write("T EST");
writer.Flush();

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

NetworkStream netStrm = new NetworkStream(s ocket);
StreamReader reader = new StreamReader(ne tStrm);
string str = reader.ReadToEn d();

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*********@ya hoo.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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.GetStrea m();
StreamWriter writer = new StreamWriter(st ream);
writer.Write("T EST");
writer.Flush();

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

NetworkStream netStrm = new NetworkStream(s ocket);
StreamReader reader = new StreamReader(ne tStrm);
string str = reader.ReadToEn d();

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
482
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 kill the offending process id. I am puzzled as to how a process that does no updating can be guilty of blocking. Typically, I think what is happening is a process that does no updates is blocking processes that are trying to do updates. Can...
3
2226
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 might have some thoughts on this perplexing .NET blocking issue. (see below) ===== Hi,
3
12274
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 nonblocking mode in c++? I did something ugly like --- c/c++ mixture --- mkfifo( "testpipe", 777);
7
17421
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 local or the remote endpoint from the client-side socket. The *really* strange thing is that Socket.LocalEndPoint is null. According to the doc, that's impossible: reading the LocalEndPoint
2
11290
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 control indefinite blocking issue. these are from MSDN. "ReadToEnd assumes that the stream knows when it has reached an end. For interactive protocols, in which the server sends data only when you ask for it and does not close the connection,...
3
1754
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 they all return. Further identical queries of this type work in 3-4 seconds (caching?) until hours later where it happens again. If I query the tables directly (without the view) I still get the same blocking. If I remove the join (it is a simple...
4
5755
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 is a quicker way of doing it. In particular I want to ensure the UI doesn't hang whilst loading, for example on a progress bar. Thanks
1
2829
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 server? I would rather not use threading or non-blocking sockets. Using VB.Net 2005.
12
29921
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.