471,330 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Re: TCP listener - check for connection status

On Wed, 06 Aug 2008 08:33:55 -0700, Markgoldin <ma*************@yahoo.com>
wrote:
tcpl = new TcpListener(ipe);
TcpClient tcpc = tcpl.AcceptTcpClient();
while (true)
{
// get data
while (true)
{
// if contidion met break;
}
}

How can I check if a client has been disconnected from the listener?
Try to send something.

Connection status can only be determined when you send data. If the
connection is broken when you send data, you'll get an exception.
Otherwise, you won't receive any notification.

You can design your protocol to send periodic "keep alive" messages, but
that's not usually the right thing to do. It's a _good_ thing that TCP
doesn't detect a broken connection until you actually try to use it. That
allows transient problems to occur without affecting your connection.

Pete
Aug 6 '08 #1
1 5434
Good answer. When you think about it, it would not even be possible without
some kind of keepalive because your never going to get any back channel
notification that the host is down or a link was broken until you actually
try to send a packet. Unless your waiting on some push notification deal, a
keepalive is not desired anyway.

--william

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Wed, 06 Aug 2008 08:33:55 -0700, Markgoldin <ma*************@yahoo.com>
wrote:
>tcpl = new TcpListener(ipe);
TcpClient tcpc = tcpl.AcceptTcpClient();
while (true)
{
// get data
while (true)
{
// if contidion met break;
}
}

How can I check if a client has been disconnected from the listener?

Try to send something.

Connection status can only be determined when you send data. If the
connection is broken when you send data, you'll get an exception.
Otherwise, you won't receive any notification.

You can design your protocol to send periodic "keep alive" messages, but
that's not usually the right thing to do. It's a _good_ thing that TCP
doesn't detect a broken connection until you actually try to use it. That
allows transient problems to occur without affecting your connection.

Pete
Aug 6 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ellen K. | last post: by
1 post views Thread by Agnes | last post: by
4 posts views Thread by Sir C4 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.