Click here to Skip to main content
15,913,337 members
Home / Discussions / C#
   

C#

 
AnswerRe: How 'cheap' is recursive use of variables ? Pin
PIEBALDconsult10-Oct-11 16:00
mvePIEBALDconsult10-Oct-11 16:00 
GeneralRe: How 'cheap' is recursive use of variables ? Pin
BillWoodruff10-Oct-11 20:15
professionalBillWoodruff10-Oct-11 20:15 
GeneralRe: How 'cheap' is recursive use of variables ? Pin
PIEBALDconsult11-Oct-11 2:33
mvePIEBALDconsult11-Oct-11 2:33 
AnswerRe: How 'cheap' is recursive use of variables ? Pin
BobJanova11-Oct-11 1:39
BobJanova11-Oct-11 1:39 
GeneralRe: How 'cheap' is recursive use of variables ? Pin
harold aptroot11-Oct-11 2:54
harold aptroot11-Oct-11 2:54 
GeneralRe: How 'cheap' is recursive use of variables ? Pin
BillWoodruff11-Oct-11 7:28
professionalBillWoodruff11-Oct-11 7:28 
QuestionTcpClient - Detecting closed connections Pin
Grimes10-Oct-11 11:32
Grimes10-Oct-11 11:32 
AnswerRe: TcpClient - Detecting closed connections Pin
BobJanova10-Oct-11 23:24
BobJanova10-Oct-11 23:24 
To understand why this is a problem, look at how a TCP connection works. It is kept alive by, essentially, ping and acknowledgement packets, and a connection is 'dropped' if no acknowledgement packets are received. (It can also be actively closed, which is different, and which closes the Socket object and gives you a 0 byte read on the input stream.) That means that if a connection is lost, the time taken for the OS to notice is dependent on how long it's prepared to wait and how often it pings the connection.

I think, if you aren't sending any data, the connection is never checked. That's why sending data into the connection provokes the exception – it makes the OS look at the connection and say 'oh, nothing has been received for a minute, it must be closed'. Sometimes it won't fail because the overall timeout hasn't expired and it hasn't done a 'ping test' so your first data packet is what triggers the 'waiting for acknowledgement' and then the connection is marked as dropped after the ack timeout (a few seconds, I think).

These issues all come about because TCP is essentially emulating a connected, stream transfer subsystem on top of a packet-based, fire and forget one (IP), and working out when a receiver has gone away in that situation is not always immediately possible.

In my sockets library I catch the exceptions (SocketException, and also ObjectDisposedException which can happen if .Net closes and disposes of the socket without telling you about it) and treat that as a disconnection.
GeneralRe: TcpClient - Detecting closed connections Pin
Grimes10-Oct-11 23:53
Grimes10-Oct-11 23:53 
GeneralRe: TcpClient - Detecting closed connections Pin
BobJanova11-Oct-11 1:26
BobJanova11-Oct-11 1:26 
GeneralRe: TcpClient - Detecting closed connections Pin
Grimes11-Oct-11 2:05
Grimes11-Oct-11 2:05 
GeneralRe: TcpClient - Detecting closed connections Pin
Grimes11-Oct-11 0:02
Grimes11-Oct-11 0:02 
GeneralRe: TcpClient - Detecting closed connections Pin
elgaabeb11-Oct-11 2:13
elgaabeb11-Oct-11 2:13 
GeneralRe: TcpClient - Detecting closed connections Pin
Grimes11-Oct-11 2:19
Grimes11-Oct-11 2:19 
GeneralRe: TcpClient - Detecting closed connections Pin
BobJanova11-Oct-11 3:20
BobJanova11-Oct-11 3:20 
AnswerRe: TcpClient - Detecting closed connections Pin
jschell11-Oct-11 9:21
jschell11-Oct-11 9:21 
GeneralRe: TcpClient - Detecting closed connections Pin
Grimes11-Oct-11 19:21
Grimes11-Oct-11 19:21 
QuestionCompare 2 Datatables Pin
jojoba2010-Oct-11 6:13
jojoba2010-Oct-11 6:13 
AnswerRe: Compare 2 Datatables Pin
André Kraak10-Oct-11 8:27
André Kraak10-Oct-11 8:27 
GeneralRe: Compare 2 Datatables Pin
jojoba2010-Oct-11 8:30
jojoba2010-Oct-11 8:30 
GeneralRe: Compare 2 Datatables Pin
André Kraak10-Oct-11 9:30
André Kraak10-Oct-11 9:30 
QuestionFire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
Tonkpils10-Oct-11 4:27
Tonkpils10-Oct-11 4:27 
AnswerRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
DaveyM6910-Oct-11 7:09
professionalDaveyM6910-Oct-11 7:09 
GeneralRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
Tonkpils13-Oct-11 4:37
Tonkpils13-Oct-11 4:37 
AnswerRe: Fire a C# Event/Delegate in C++, or: EventHandling via DLL Pin
TheGreatAndPowerfulOz10-Oct-11 12:13
TheGreatAndPowerfulOz10-Oct-11 12:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.