Delphi 7中 TIdUDPServer 的接收端怎么写代码?

叽哥飞 2014-12-15 05:02:47
我在发送端写下这样的代码

unit Unit1;

interface

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

type
TForm1 = class(TForm)
IdUDPServer1: TIdUDPServer;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure IdUDPServer1Status(ASender: TObject;
const AStatus: TIdStatus; const AStatusText: String);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
IdUDPServer1.Send('10.95.162.165',2000,'123456');
end;

procedure TForm1.IdUDPServer1Status(ASender: TObject;
const AStatus: TIdStatus; const AStatusText: String);
begin
showmessage('received');
end;

end.

那接收端就应该怎样接收了?
...全文
804 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gdxg0762 2015-03-06
  • 打赏
  • 举报
回复
procedure TfrmDM.IdUDPServer1UDPRead(Sender: TObject; AData: TStream; ABinding: TIdSocketHandle); var i, DataLen : Integer ; buf : array[0..1023] of Byte ; s : String ; begin DataLen := AData.Size ; if DataLen = 0 then Exit ; AData.ReadBuffer(buf,AData.Size) ; if (Chr(buf[0]) = '$') and (Chr(buf[1]) = '$') then OnReceiveData(@buf,DataLen);
天轶 2015-03-02
  • 打赏
  • 举报
回复
楼上正解,OnUDPRead事件就是。
goease 2014-12-16
  • 打赏
  • 举报
回复
不过我建议不要用TIdUDPServer同时进行收发,有时候会不顶用。我一般只用它来接数据,发数据用别的
goease 2014-12-16
  • 打赏
  • 举报
回复
不是有OnUDPRead事件么?

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧