使用idudpserver和idudpclient编写的程序出现奇怪问题,请高手指点

iiprogram 2003-01-02 10:50:02
这是两个很简单的测试udp 传输的程序,结果:
当client发送消息后,监听程序只能收到一半消息(例如:8条受到4条)
请高手看看,是什么问题:
-----------------------------------------
server(监听部分如下):
(监听端口和ip都已经设好)
unit Unit1;

interface

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

type
TForm1 = class(TForm)
IdUDPServer1: TIdUDPServer;
Label1: TLabel;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
StatusBar1: TStatusBar;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
IdUDPServer1.Active:=TRUE;
StatusBar1.SimpleText:='Server is listening on port 39213';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
IdUDPServer1.Active:=FALSE;
StatusBar1.SimpleText:='Server is down!'
end;

procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var ReceiveData :string ;
var SendData :string;
var VPeerIp : string;
var VPeerPort : integer;
begin
ReceiveData:=IdUDPServer1.ReceiveString(VPeerIp,VPeerPort,-1);
Memo1.Lines.Add(ReceiveData);
Memo1.Lines.Add(VPeerIp);
Memo1.Lines.Add(inttostr(VPeerPort));

end;

end.

-----------------------------------------
client(发送端):
注: idudpclient的port和host 都设好了.
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient;

type
TForm1 = class(TForm)
Bevel1: TBevel;
Label1: TLabel;
Memo1: TMemo;
Button1: TButton;
Memo2: TMemo;
Label2: TLabel;
Label3: TLabel;
IdUDPClient1: TIdUDPClient;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var SendData :string;
begin
SendData:=Memo1.Lines.Text;
idUDPClient1.Send(SendData);

end;

end.


请哪位高手帮忙解决,谢谢!
...全文
24 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
phoenix_l 2003-07-03
var
DataStringStream: TStringStream;

DataStringStream.CopyFrom(AData, AData.Size);
这样就可以得到你需要的信息
回复
iiprogram 2003-01-02
up
回复
发动态
发帖子
网络通信/分布式开发
创建于2007-08-02

1566

社区成员

Delphi 网络通信/分布式开发
申请成为版主
社区公告
暂无公告