(Ying-Shen Yu[MSFT])
6/21/2004 5:32:00 AM
Hi Jim,
From your description, I'd like to confirm if my understanding is correct,
you are trying to determine if a client is able to connect to certain
server, not just if a client has a network connection( which might not be
able to connect to the destination server) , is it correct?
IMO, there is no better way to resolve this issue, the tcp "connection" is
simulated by "time-out and retry" mechanism on the two end points, the
underlying network routers do not have the concept of connection state, in
other words, we could not know a tcp connection failure until we get
timeout when we try to send something to the destination.
Your current solution is ok. If you can reach the destination server using
ping command , you may try P/Invoking the IsDestinationReachable API, it
provides a similiar function by sending ping packets to the destination and
return a boolean value instead of exception, maybe it could reduce the
performance penalty somehow. You may define the P/Invoke definition of
this API in C# like below:
//bool bReachable = IsDestinationReachable("www.microsoft.com",IntPtr.Zero);
[DllImport("sensapi.dll")]
private extern static bool IsDestinationReachable(string dest,IntPtr ptr);
Ofcourse, many servers turned off the Ping response for security concerns,
if this is the case, maybe we at least could polling the status in a
seperate thread.
Also, If both the server and clients are in the same LAN, maybe you can try
making a "heartbeat" program on the server side, this program could create
a multicast group and send echo message to the group address periodically,
then the client could get the connection status by receiving echo messages.
If you still have problem on this issue, please feel free to replyl this
thread.
Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.