K
Keith Langer
Hi,
I've noticed that the behavior of ReceiveTimeout has changed
between .Net 1.1 and .Net 2.0 when it comes to the GetStream.Read
method. In .Net 1.1, if the timeout period elapsed, I would get a
System.IO.IOException, but the connection stayed open. I could then
check the InnerException for Errorcode 10060 to verify that it was a
timeout. In .Net 2.0, I still get an IOException when there's a
timeout, but this time the socket closes. This means I would have to
reestablish the connection when I didn't need to before (or worse yet,
if I'm not controlling the connection, then I have to wait for the
other end to reconnect. Is there a way to avoid the disconnects?
Below is some sample code
m_tcpClient.ReceiveTimeout = 5000
try
intCount = m_tcpClient.GetStream.Read(bytData, 0, DATA_SIZE)
If intCount > 0 Then
'Got data
Else
'intCount = 0 means the connection was closed at the other end
ShowMessage("Lost connection")
blnReset = True
End If
Catch ex As System.IO.IOException
If TypeOf ex.InnerException Is SocketException AndAlso
CType(ex.InnerException, SocketException).ErrorCode = 10060 Then
'This should mean that we had a timeout
'for some reason, in .Net 2.0 I am getting a disconnect after a
timeout. For now, reset connection
End If
end try
thanks,
Keith Langer
I've noticed that the behavior of ReceiveTimeout has changed
between .Net 1.1 and .Net 2.0 when it comes to the GetStream.Read
method. In .Net 1.1, if the timeout period elapsed, I would get a
System.IO.IOException, but the connection stayed open. I could then
check the InnerException for Errorcode 10060 to verify that it was a
timeout. In .Net 2.0, I still get an IOException when there's a
timeout, but this time the socket closes. This means I would have to
reestablish the connection when I didn't need to before (or worse yet,
if I'm not controlling the connection, then I have to wait for the
other end to reconnect. Is there a way to avoid the disconnects?
Below is some sample code
m_tcpClient.ReceiveTimeout = 5000
try
intCount = m_tcpClient.GetStream.Read(bytData, 0, DATA_SIZE)
If intCount > 0 Then
'Got data
Else
'intCount = 0 means the connection was closed at the other end
ShowMessage("Lost connection")
blnReset = True
End If
Catch ex As System.IO.IOException
If TypeOf ex.InnerException Is SocketException AndAlso
CType(ex.InnerException, SocketException).ErrorCode = 10060 Then
'This should mean that we had a timeout
'for some reason, in .Net 2.0 I am getting a disconnect after a
timeout. For now, reset connection
End If
end try
thanks,
Keith Langer