Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. System.IO.IOException A connection attempt failed because the connected party did not
  2. properly respond after a period of time, or established connection failed because
  3. connected host has failed to respond.
  4.  
  5. public byte[] Receive()
  6. {
  7. byte[] readBuffer = new byte[1024];
  8. byte[] realReceivedBytes = new byte[0];
  9. try
  10. {
  11. if (NetworkStream.CanRead)
  12. {
  13. int receivedBytesCount = 0;
  14. receivedBytesCount = NetworkStream.Read(readBuffer, 0, 1024);
  15. realReceivedBytes = new byte[receivedBytesCount];
  16. Array.Copy(readBuffer, 0, realReceivedBytes, 0, receivedBytesCount);
  17. }
  18. return realReceivedBytes;
  19. }
  20. catch (System.IO.IOException ex)
  21. {
  22. throw ex;
  23. }
  24. catch (Exception ex)
  25. {
  26. throw ex;
  27. }
  28. }
  29.  
  30. catch (System.IO.IOException)
  31. {
  32. if (!client.Connected)
  33. {
  34. Log("Client is not connected to host anymore.");
  35. break;
  36. }
  37. else
  38. {
  39. Log(String.Format("Error connecting to host. Retry attempt no. {0}",
  40. (numTries + 1)));
  41. Thread.Sleep(100);
  42. numTries++;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement