如果你要真实的体现Internet在线,不要用UDP了,用TCP,代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient;
type
TForm1 = class(TForm)
IdTCPClient1: TIdTCPClient;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
idtcpclient1.Host := '202.108.249.206'; //CCTV
idtcpclient1.Port := 80;
try
idtcpclient1.Connect;
idtcpclient1.Disconnect;
showmessage('在线');
except
showmessage('请检查网络');
end;
end;
end.