关于网络连通的问题

mmm00000 2004-10-29 08:25:17
一般情况下,就是利用ping来检测网络连通。不过这样需要指定一个IP,一旦这个地址受到攻击或者网络的短暂迟缓,就会不可靠
能否通过检测在一定时间内收到的数据包大小来判断网络连通是否呢
...全文
134 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
kingzai 2004-11-03
  • 打赏
  • 举报
回复
基本上用InternetGetConnectedState API判断就行了,当然ping是最直接的
mmm00000 2004-10-29
  • 打赏
  • 举报
回复
To eastnofail(Char *) :
虽然看的头晕,不过还是很感谢你~
过两天回来慢慢研究

To bcb_alone(孤心) :
握手机制只是听说过,能解释一下么
我去搜索,结果又是系统维护~晕
TypeCsdnLearn 2004-10-29
  • 打赏
  • 举报
回复
学习,请高手来点代码分析一下
lidawen 2004-10-29
  • 打赏
  • 举报
回复
學習
bcb_alone 2004-10-29
  • 打赏
  • 举报
回复
也可以使用心跳(也就是握手机制)
定时发送数据来检测。
eastnofail 2004-10-29
  • 打赏
  • 举报
回复
From: Allen Weng <yweg_spawa@microsoft.com>
Subject: RE: Detecting if internet connection is active at this moment.
Date: Friday, May 04, 2001 2:26 AM

Actually, there is no single function for determining if a machine is
connected to the Internet, and it is impossible to reliably determine what
is happening without side effects - such as automatic network connections
taking place. What you can do is reliably detect when there definitely
isn't an Internet Link: in the absence of any dial up or LAN connection the
system is definitely off line.

Some techniques include:

1. IsNetworkAlive()
If you are targeting system with IE5 or later, this is the best API call
yet it even listens for traffic on a LAN. There is a secondary function
IsDestinationReachable() which tries to resolve the hostname and ping it.
This does not work through firewalls, and overestimates speed as the max
the LAN card can support, rather than the actual point to point bandwidth.

2. RasEnumConnections()
A reliable technique for modems and direct dial up networking, but not for
situations where Internet access is via a LAN. You should dynamically load
"RasEnumConnectionA" from "RASAPI32.DLL", as LAN installations of Windows
may not include the library.

3. InternetGetConnectedState()
This Wininet /IE4 function call can distinguish between modem and LAN, but
can't handle complex LAN+autodial router situations. It is "offline state
aware". Important: handling of the offline flage changed for IE5 -it
returns TRUE for connected' even when off line, but signals the flags in
the LPDWORD parameter.

4. InternetCheckConnection()
A Winnet/IE4 function call. This is meant to determine if a URL is
reachable- in practice it is pretty unreliable and best voided.

5. NT SP4, NT5: The IP helper API can tell you which network interface to
use to connect to a supplied IP address, and what the bandwidth and current
status of that link is

6. Using the Offline flag which is part of IE4 to allow users to manually
control the online/offline state of applications. This flag is stored in
the registry and can be manipulated via some funcions calls

These calls mostly determine the presence or absence of network connections
-not Internet access, so can't handle a home network sharing a dial up
connection, or two laptops connected directly to each other.

The global offline state flag of IE4 (and hence win98, NT5) and the call to
test it - InternetGetConnectedState()- look the best long term options, but
will take time to become universal. The IP Helper APIs even let you find
out how much traffic is going over a link, but only detect the 'loopback'
interface on Windows 98, so is not a lot of use. Wouldn't a
'GetSpeedToHost() function call be great?

Finally, whatever technique you use, when it's time to talk to a remote
site, always add timeouts or a cancel button. Even a quick functions like
gethostbyname() can lock up an app if something in the network chain is
broken.

Allen Weng
Microsoft Developer Support




eastnofail 2004-10-29
  • 打赏
  • 举报
回复
IsNetworkAlive

The IsNetworkAlive function determines whether the local system is connected to a network and the type of network connection. For example, whether the local system has connectivity to a LAN, WAN, or both networks.


Bool IsNetworkAlive(
LPDWORD lpdwFlags
);

Parameters
lpdwFlags
[in] Provides information on the type of network connection available when the return value is TRUE. The flags can be:

NETWORK_ALIVE_LAN
The computer has one or more LAN cards that are active.
NETWORK_ALIVE_WAN
The computer has one or more active RAS connections.
NETWORK_ALIVE_AOL
This flag is only valid in Windows 95 and Windows 98. Indicates the computer is connected to the America Online network.
Return Values
TRUE
The local system is connected to a network.
FALSE
Call GetLastError to determine the reason for no connectivity.
1)计算机网络的工作原理 计算机网络工作原理是将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源共享和信息传递。 计算机网络向用户提供的最重要的功能有两个,即连通性、共享和安全性。 2)计算机网络作用 数据通信是计算机网络最基本的功能。它用来快速传送计算机与终端、计算机与计算机之间的各种信息,包括文字信件、新闻消息、咨询信息、图片资料、报纸版面等。 利用这一特点,可实现将分散在各个地区的单位或部门用计算机网络联系起来。进行统一的调配、控制和管理。 资源共享包括计算机硬件资源、软件资源和数据资源的共享,硬件资源的共享提高了计算机硬件资源的利用率,由于受经济和其他因素的制约,这些硬件资派不可能所有用户都有,所以使用计算机网络不仅可以使用自身的硬件资源,也可共享网络上的资源。 提高系统的可靠性,在单机使用的情况下,任何一个系统都可能发生故障,这样就会为用户带来不便,而当计算机联网后,各计算机可以通过网络互为后备,一旦某台计算机发生故障,则由别处的计算机代为处理,还可以在网络的一些结点上设置一定的备用设备。 计算机网络 基础概念 详解(1/12) 计算机网络 物理层 实现的功能详解(2/12) GNS3 和 VMWare 搭建实验环境(3/12) 计算机网络 数据链路层 实现的功能详解(4/12) IP地址和子网划分(5/12) 计算机网络 网络层 静态路由和动态路由协议(6/12) 计算机网络 网络层协议 实现的功能详解(7/12) 计算机网络 传输层 TCP 和 UDP 协议(8/12) 计算机网络 应用层 诸多协议 实验环境搭建(9/12) 网络安全与措施(10/12) IPv6和IPv4 共融技术(双协议栈、隧道技术和NAT技术等)(11/12) 搭建流媒体服务和实用无线网络(存储式和实况式流媒体;对等和热点无线)(12/12)

1,316

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧