【例子介绍】
通过UPD协议监控客户机是否在线,以及是否运行指定进程
【相关图片】
【源码结构】
procedure TMainForm._ReHandSign(HandDataPackage:THandDataPackage);
var
_HandDataPackage:THandDataPackage;
PublicIp:string;
PublicPort:integer;
begin
_HandDataPackage:=HandDataPackage;
_HandDataPackage.Head.SendType:=Server;
_HandDataPackage.Head.ReceverType:=Client;
_HandDataPackage.Head.ComType:=ReHandSign;
_HandDataPackage.Head.DataLen:=SizeOf(_HandDataPackage);
PublicIp:=_HandDataPackage.Body.IP;
PublicPort:=_HandDataPackage.Body.Port;
Try
IdUDPS.SendBuffer(PublicIp,PublicPort,_HandDataPackage,sizeof(_HandDataPackage));
except
end;
end;
procedure TMainForm.IdUDPSUDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
Head:THead;
HandData:THandData;
HandDataPackage:THandDataPackage;
i:integer;
s:string;
begin
AData.ReadBuffer(Head, SizeOf(Head));
case (Head.ComType) of
//接收到客户端发出的握手请求
HandSign:begin
FillChar(HandData.MachineName, 15, 0);
AData.ReadBuffer(HandData, SizeOf(HandData));
评论