O
ounettiger
Unregistered / Unconfirmed
GUEST, unregistred user!
我用INDY10(版本:10.1.6)做个通讯程序,大家看一下源代码,帮我分析一下是什么问题,100分相送,分不够咱再加:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdUDPClient, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPServer, IdSocketHandle,IdGlobal, IdAntiFreezeBase, IdAntiFreeze;
type
TForm1 = class(TForm)
IdUDPServer1: TIdUDPServer;
IdUDPClient1: TIdUDPClient;
Button1: TButton;
Edit1: TEdit;
IdAntiFreeze1: TIdAntiFreeze;
procedure Button1Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TIdBytes; ABinding:
TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
mmbyte:TIdBytes;
str:string;
begin
IdUDPClient1.Host:=Edit1.Text;
IdUDPClient1.ReceiveTimeout:=250;
IdUDPClient1.Active:=True;
IdUDPClient1.Connect;
if IdUDPClient1.Connected then IdUDPClient1.Send('READY_?');
IdUDPClient1.ReceiveBuffer(mmbyte);
BytesToRaw(mmbyte,str,Length(mmbyte));
ShowMessage(IntToStr(Length(mmbyte)));
//if IdUDPClient1.ReceiveString()='READY_OK' then ShowMessage('Connected');
end;
procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TIdBytes;
ABinding: TIdSocketHandle);
var
sbyte:TIdBytes;
sstr:array[0..10] of char;
begin
sstr:='READY_OK';
sbyte:=RawToBytes(sstr,Length(sstr));
if string(adata)='READY_?' then
begin
ABinding.SendTo(ABinding.PeerIP,ABinding.PeerPort,AData);
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdUDPClient, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPServer, IdSocketHandle,IdGlobal, IdAntiFreezeBase, IdAntiFreeze;
type
TForm1 = class(TForm)
IdUDPServer1: TIdUDPServer;
IdUDPClient1: TIdUDPClient;
Button1: TButton;
Edit1: TEdit;
IdAntiFreeze1: TIdAntiFreeze;
procedure Button1Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TIdBytes; ABinding:
TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
mmbyte:TIdBytes;
str:string;
begin
IdUDPClient1.Host:=Edit1.Text;
IdUDPClient1.ReceiveTimeout:=250;
IdUDPClient1.Active:=True;
IdUDPClient1.Connect;
if IdUDPClient1.Connected then IdUDPClient1.Send('READY_?');
IdUDPClient1.ReceiveBuffer(mmbyte);
BytesToRaw(mmbyte,str,Length(mmbyte));
ShowMessage(IntToStr(Length(mmbyte)));
//if IdUDPClient1.ReceiveString()='READY_OK' then ShowMessage('Connected');
end;
procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TIdBytes;
ABinding: TIdSocketHandle);
var
sbyte:TIdBytes;
sstr:array[0..10] of char;
begin
sstr:='READY_OK';
sbyte:=RawToBytes(sstr,Length(sstr));
if string(adata)='READY_?' then
begin
ABinding.SendTo(ABinding.PeerIP,ABinding.PeerPort,AData);
end;
end;
end.