neda khooyriz

neda khooyriz

  • NA
  • 5
  • 5.1k

error of reading data in socket programming

Apr 13 2014 2:36 AM
i wrote a console application. i used socket programming . i get error in below cod. transfer speed of data is 10ms . after a period of time i get a error on " while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)" line .
while (true) {
TcpClient tcpClient = tcpListener.AcceptTcpClient();
NetworkStream stream = tcpClient.GetStream(); 
String data = null; int i; while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) { // Translate data bytes to a ASCII string.  data = System.Text.Encoding.ASCII.GetString(bytes, 0, i); Console.WriteLine("Received: {0}", data); ... }
 error:
An unhandled exception of type 'System.IO.IOException' occurred in System.dll Additional information: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Answers (2)