Click here to Skip to main content
15,917,062 members
Home / Discussions / C#
   

C#

 
GeneralRe: How 'cheap' is recursive use of variables ? Pin
BillWoodruff10-Oct-11 20:19
professionalBillWoodruff10-Oct-11 20:19 
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 
Hello there.

I am currently writing a server and client application. I have code that can handle it when client users close their connection, however detecting when the connection has closed due to an error is a completely different story. What is the best way to do this?

I had a look at the forum and found similar questions. One of these propose that I use the Linger and Time Out properties of TCPClient to determine whether the connection is still open. What I read from MSDN about these properties are that they determine the time that write/read operations may wait to complete. To me this does not seem like a good way to test the connection, because shortening these times might close connections when in actual fact the remote connection hasn't disconnected but is merely very busy. Am I wrong? Is my understanding of lingering and time outs correct?

Another solution proposes that I use polling to determine whether the connections are open. This is actually what I am currently doing. My server has a thread that every once in a while sends a small piece of test data to every connection. I then try and catch the IOException exceptions that are thrown when I send data to a connection that closed at the client side. This seems to work for the most part, however, it does not throw immediately when I send the test data, it seems to throw randomly on the 2nd or 3rd set of test data. Only after it has thrown does the server's TCPCLient.Connected property change to false. How can I get the connection to immediately throw the exception? Could there be a better way to fix this and to see if the connection has closed?

Any Help is appreciated

Thanks!
KOM UIT DAAAAA!!!

AnswerRe: TcpClient - Detecting closed connections Pin
BobJanova10-Oct-11 23:24
BobJanova10-Oct-11 23:24 
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 

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.