You'd know because your packets are being delivered and you're not getting
exceptions. It's the equivalent of saying, "How do I know if my phone call
is still connected?" Well, you'd usually say something like "Are you
there?" and the other party would respond, "Yes, I'm here." If you just sit
there quietly without saying anything, you'd never know if there was a
connection unless you kept getting data from your talkative friend. If he
just sits there quietly, you'd never know. Of course, this isn't a perfect
parallel, as the phone system uses voltages to indicate if there's really a
connection there, but you get the idea.
There's no way to know immediately if there's a loss of data. If you're
streaming timely data, all you can do is see if data is arriving in a timely
manner by having the other end acknowledge it and make sure that you get
your acknowledgement as fast as you need to get it to indicate that
everything is fast enough. Remember that TCP itself does *NOT* guarantee
any particular timeliness of delivery. It simply guarantees that all
packets that can be delivered will be delivered, in the order they were
sent, or that you'll be notified as soon as the attempted delivery times
out. If you need more information or more-detailed information than that,
you have to do that yourself, on top of TCP or UDP.
TCP itself will only report a broken connection in the way I said, by
throwing an exception when it detects that the connection is closed. You
can set up keep-alives, as Scott indicated, which can give you some
indication that a socket on which you are simply waiting for incoming data
has broken (it sends "Are you there?" packets behind the scenes periodically
and shuts down the socket if the other end doesn't repond repeatedly; this
is *NOT* done on a millisecond by millisecond basis, however, so it won't
tell you anything immediately; the default is not to even start asking, "Are
you there?" for two hours after the socket goes idle).
Paul T.
You can't know that in all cases. It's impossible. As indicated, you can
send the data and wait to see if there's an exception. You can detect, by
looking for SYN, whether the server cleanly broke the connection, but this
is not a suitable general-purpose detection mechanism for broken
connections. If I go just past your Ethernet switch and cut the cable, you
won't ever get that SYN indication. The only indication that you'll ever
get
that send is not possible is when you get a time-out for a sent packet
that
was never acknowledged because the cable was cut.
So, with that information in hand, why do you need to verify continuity of
the connection before sending? I never do that and all of my network
programs work just fine.
Paul T.
Hi !
I need to know if the connection is alive or not before send my data.
When the TCP connection is established the
TcpConnectionInformation.status return "Established", if the server go
down the TcpConnectionInformation.status return "SynSent". Like this i
can know if the connection is down (and raise the alarm before the
user try to send the data).
The host port and remote port showing by the TcpConnectionInformation
are the external/random ports, not the port that i have set as
endpoint (ip
ort).
I dont know how TcpConnectionInformation work. But the MSDN example
can help me to identify my TCPconnection among others ? Have you the
link?
If i can obtain this informations using the Socket class, can you send
me a little example ? I am really desperate !
Thankyou very much !
Ale
Ok Paul
help me to understand: how can know if the connection is up (and the
cable is not cut) without wait the timeout ?
I need immediately know if there's a possible loss of data (for
example with OpenNETCF.Net.AdapterNotification class i immediately
know if you cut my cable).
But i'm confused, which is the right way? What is the suitable
detection mechanism for broken connections?
Thankyou very much.
Ale