DELPHI中如何向某个IP不间断的发送数据


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, IdUDPClient, IdBaseComponent, IdComponent,
IdUDPBase, IdUDPServer, IdSocketHandle;

type
TForm1 = class(TForm)
Button1: TButton;
IdUDPServer1: TIdUDPServer;
IdUDPClient1: TIdUDPClient;
Memo1: TMemo;
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
str: pchar;
pos: Integer;
begin
pos := AData.Size;
str := AllocMem(pos);
AData.ReadBuffer(str^, pos);
self.Memo1.Lines.Add(Str);
FreeMem(str);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
self.IdUDPClient1.Active := false;
self.IdUDPClient1.Active := True;
self.IdUDPClient1.Send('hello my friend');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
self.IdUDPServer1.DefaultPort := 5000;//接受数据端口  www.delphitop.com 搜集整理
self.IdUDPClient1.Port := 5000;
self.IdUDPClient1.Host := '127.0.0.1';//目标机器IP
self.IdUDPServer1.Active := True;
self.IdUDPClient1.Active := True;
end;

end.
联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678