请教一个关于TIdUDPClient和TIdUDPServer的问题,谢谢(0分)

  • 主题发起人 主题发起人 hey777
  • 开始时间 开始时间
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.
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2466550
到这里看看吧!
 
问题已解决,谢谢:)
应该把
IdUDPClient1.Active := true;
IdUDPServer1.Active := true;放在最后
 

Similar threads

I
回复
0
查看
683
import
I
I
回复
0
查看
510
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部