H
hey777
Unregistered / Unconfirmed
GUEST, unregistred user!
IdUDPClient, IdUDPServer在程序中创建,client发出的数据server收不回来,大家帮忙看看,谢谢 :)
type
TCharArray = array[0..8191] of Char;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
IdUDPClient1: TIdUDPClient;
IdUDPServer1: TIdUDPServer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: boolean;
j: integer;
begin
IdUDPClient1.Send('test');
end;
procedure TForm1.UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
buf : TCharArray;
l : integer;
s: string;
begin
if AData.Size > 0 then
begin
l := Min(AData.Size, SizeOf(buf));
AData.Read(buf, l);
SetString(s, PChar(@buf), l);
Edit1.Text := s;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
IdUDPClient1 := TIdUDPClient.Create(nil);
IdUDPServer1 := TIdUDPServer.Create(nil);
IdUDPClient1.Active := true;
IdUDPServer1.Active := true;
IdUDPClient1.BufferSize := 8092;
IdUDPServer1.BufferSize := 8092;
IdUDPClient1.Host := '127.0.0.1';
IdUDPClient1.Port := 5568;
IdUDPServer1.DefaultPort := 5568;
IdUDPServer1.OnUDPRead := UDPRead;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
IdUDPClient1.Free;
IdUDPServer1.Free;
end;
end.
type
TCharArray = array[0..8191] of Char;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
IdUDPClient1: TIdUDPClient;
IdUDPServer1: TIdUDPServer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i: boolean;
j: integer;
begin
IdUDPClient1.Send('test');
end;
procedure TForm1.UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var
buf : TCharArray;
l : integer;
s: string;
begin
if AData.Size > 0 then
begin
l := Min(AData.Size, SizeOf(buf));
AData.Read(buf, l);
SetString(s, PChar(@buf), l);
Edit1.Text := s;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
IdUDPClient1 := TIdUDPClient.Create(nil);
IdUDPServer1 := TIdUDPServer.Create(nil);
IdUDPClient1.Active := true;
IdUDPServer1.Active := true;
IdUDPClient1.BufferSize := 8092;
IdUDPServer1.BufferSize := 8092;
IdUDPClient1.Host := '127.0.0.1';
IdUDPClient1.Port := 5568;
IdUDPServer1.DefaultPort := 5568;
IdUDPServer1.OnUDPRead := UDPRead;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
IdUDPClient1.Free;
IdUDPServer1.Free;
end;
end.