I have created a Streaming based application where my requirement is to send the Live recorded data to the server. The data is sent via Network Stream object under TCP Client.
The server analyzes the data in real time and sends the chunked response to the client. My application sends data continously to the server until it checks for NetworkStream.DataAvailable method. The response data from server if received in chunks I have to make two read calls to the Network Stream object. In the second read the network stream object throws an exception ?????. I am not sure why because the network stream object still shows the data available property to true.
Below is the snippet of code used which is not a rocket science.
//Write the data to network stream
public ERRORCODE WriiteToStream(byte data)
bool isAvailable = _networkStream.DataAvailable;
if (isAvailable == true)
//32 KB Buffer for reading the data
byte dataFrmServer = new byte[BUFFER];
int dataRead = _networkStream.Read(dataFrmServer, 0, dataFrmServer.Length);
//Best fit buffer for data in 32 KB buffer
byte DataRead = new byte[dataRead];
Array.Copy(dataFrmServer, 0, DataRead, 0, dataRead);
resultBuffer = resultBuffer + System.Text.
Encoding.ASCII.GetString(DataRead, 0, DataRead.Length);
//Writing Data on Network Stream
_networkStream.Write(data, 0, data.Length);
catch (Exception ex)
In the above code HaveResponse just checks if the end of data flag has been received from the server and returns true or false.
Can anyone tell me what is wrong with the above code ???
- Changed type warrentangModerator Tuesday, June 30, 2009 8:27 AM
Thanks for the reply.
Well, I receive the socket exception with code 10054.
I tried to run a sample app in full framework 2.O which allows multiple reading and seems to work fine..
I captured the network traffic using ethereal it shows the complete server response which doesn't reach the application.
Exact Exception received is as below : at System.Net.Sockets.Socket.ReceiveNoCheck() at System.Net.Sockets.Socket.Receive() at System.Net.Sockets.NetworkStream.Read() at SocketTestRecordingStreaming.SocketCommunication.GetResponse() I hope the above exception could could answer your query.
Did you look up the error code? "An existing connection was forcibly closed
by the remote host".
"Swapnil Jain" <=?utf-8?B?U3dhcG5pbCBKYWlu?=> wrote in message
> Hi ,
> Thanks for the reply.
> Well, I receive the socket exception with code 10054.
> I tried to run a sample app in full framework? 2.O which allows multiple
> reading and seems to work fine..
> I? captured the network traffic using ethereal? it shows the complete?
> server response? which doesn't reach the application.
We are changing the issue type to "General Discussion" because you have not followed up with the necessary information. If you have more time to provide more information, please feel free to change the issue type back to "Question". If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.
Please mark the post that helps you, and unmark that does not. This benefits our community members.
Correct me if I'm wrong (it's been a while since I looked at this), but I remember DataAvailable and Connected properties on these classes not functioning as advertised by the documentation.
You should probably just rely on using the read/write methods to determine connectivity and refactor your code to handle no data and exceptions appropriately.
Just googling quickly I think some details are here: