unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient;
type
TCommBlock =
record
SenderName,
Msg :
string
[
100
];
end
;
TForm1 =
class
(TForm)
Panel2: TPanel;
Memo2: TMemo;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
IdUDPClient1: TIdUDPClient;
LabeledEdit3: TLabeledEdit;
Button3: TButton;
Button4: TButton;
procedure
Button1Click(Sender: TObject);
procedure
Button2Click(Sender: TObject);
procedure
Button3Click(Sender: TObject);
procedure
Button4Click(Sender: TObject);
private
public
end
;
var
Form1: TForm1;
implementation
const
RECIEVETIMEOUT =
5000
;
{$R *.dfm}
procedure
TForm1
.
Button1Click(Sender: TObject);
begin
IdUDPClient1
.
Host:=LabeledEdit1
.
Text;
IdUDPClient1
.
Port:=StrToInt(LabeledEdit2
.
Text);
IdUDPClient1
.
ReceiveTimeout:=RECIEVETIMEOUT;
end
;
procedure
TForm1
.
Button2Click(Sender: TObject);
var
Comm:TCommBlock;
begin
Comm
.
SenderName:=LabeledEdit3
.
Text;
Comm
.
Msg:=Memo2
.
Lines
.
Text;
Memo1
.
Lines
.
Add(Comm
.
SenderName+
':'
+ Comm
.
Msg);
IdUDPClient1
.
SendBuffer(Comm,sizeof(Comm));
end
;
procedure
TForm1
.
Button3Click(Sender: TObject);
begin
Close;
end
;
procedure
TForm1
.
Button4Click(Sender: TObject);
begin
Memo1
.
Clear;
end
;
end
.
请发表评论