UDP就比较简单了,放个按钮,一个TIdUDPServer
TIdUDPServer绑定 0.0.0.0:3820,然后Active设置为True//发送按钮procedure TForm1.Button1Click(Sender: TObject);varIdUDPClient1: TIdUDPClient; //动态创建TIdUDPClientbeginIdUDPClient1:=TIdUDPClient.Create;IdUDPClient1.BroadcastEnabled:=true;tryIdUDPClient1.Port:=3820;IdUDPClient1.Host:='127.0.0.1';IdUDPClient1.Connect; //实际上就这三句IdUDPClient1.Send('abcdefg.'); //2IdUDPClient1.Disconnect; //3finallyIdUDPClient1.Free;end;end;//IdUDPServer1 绑定3820端口//注意引用 IdSocketHandle, IdGlobalprocedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TBytes;ABinding: TIdSocketHandle);begin
Memo1.Lines.Add(BytesToString(AData)); //把接收的信息加到Memo1end;