string strServerIp="192.168.0.45";//为主机IP地址
int iDataPort=80;
Socket clientSocket =new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
bool bResult=clientSocket.Connect(new IPEndPoint(Dns.Resolve(strServerIP).AddressList[0],iDataPort));
if(bResult)
{
//连接成功
}
else
{
//连接失败
}
---- 若InternetGetConnectedState函数返回True,则为在线状态。该方法最大的缺点是:若当前连接不是用wininet方法建立的,则返回值可能不准确。
[DLLImport (""")]
private extern static bool InternetGetConnectedState(out int connectionDescribtion,int reservedValue)