what to do after a read from a socket Timeout
-
Hi All I am using
TcpClient
to read from a socket and I set the propertyReceiveTimeout
to a value let's say 3 seconds. As per documentation, after the read fails because of a Timeout, anIOexception
is thrown. After that point, each time I callReadLine
the exception is systematically thrown again and again. What to do to reset the Timeout value or to renable the reading from a socket with no worry? I reset a new value forReceiveTimeout
but it doesn't work. Do you know what to do? -
Hi All I am using
TcpClient
to read from a socket and I set the propertyReceiveTimeout
to a value let's say 3 seconds. As per documentation, after the read fails because of a Timeout, anIOexception
is thrown. After that point, each time I callReadLine
the exception is systematically thrown again and again. What to do to reset the Timeout value or to renable the reading from a socket with no worry? I reset a new value forReceiveTimeout
but it doesn't work. Do you know what to do?Don't know if this will help you or not..... I have a UDP client based application. We were having troubles reconnecting the computers when one of the network cards would go down for some reason. What I ended up doing was checking for exceptions, and depending on the exceptions, I would then try closing/reopening the socket. Maybe this is what you need to do. You should also probably test for the case I had which was to have the apps communicating, and then disable the network adapter and reenable it.
-
Hi All I am using
TcpClient
to read from a socket and I set the propertyReceiveTimeout
to a value let's say 3 seconds. As per documentation, after the read fails because of a Timeout, anIOexception
is thrown. After that point, each time I callReadLine
the exception is systematically thrown again and again. What to do to reset the Timeout value or to renable the reading from a socket with no worry? I reset a new value forReceiveTimeout
but it doesn't work. Do you know what to do?i don't think the exception is thrown because of the ReceiveTimeout.. if nothings availible to read the buffer would be empty and that would may by throw an exception.. try to check before reading using the property
if (client.DataAvailable > 0) { ... string line = client.ReadLine(); ... }
-
Hi All I am using
TcpClient
to read from a socket and I set the propertyReceiveTimeout
to a value let's say 3 seconds. As per documentation, after the read fails because of a Timeout, anIOexception
is thrown. After that point, each time I callReadLine
the exception is systematically thrown again and again. What to do to reset the Timeout value or to renable the reading from a socket with no worry? I reset a new value forReceiveTimeout
but it doesn't work. Do you know what to do?A timeout closes the connection. You have to re-establish the connection. Make sure your TcpClient has keepalive set to true, and make sure the server isn't timing out on you. Also, a higher timeout value can help unless there is a major issue with the server timing out, in which case you will just wait longer for the exception.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
i don't think the exception is thrown because of the ReceiveTimeout.. if nothings availible to read the buffer would be empty and that would may by throw an exception.. try to check before reading using the property
if (client.DataAvailable > 0) { ... string line = client.ReadLine(); ... }
-
A timeout closes the connection. You have to re-establish the connection. Make sure your TcpClient has keepalive set to true, and make sure the server isn't timing out on you. Also, a higher timeout value can help unless there is a major issue with the server timing out, in which case you will just wait longer for the exception.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane