我是个新手,求助各位大哥帮忙??
我用的是udpclient,udpserver两个组件,在uses里添加了winsock后,执行报错!!
源程序如上:
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdUDPServer, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient, Buttons,WinSock;type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
IdUDPClient1: TIdUDPClient;
IdUDPServer1: TIdUDPServer;
Memo1: TMemo;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations } end;
var
Form1: TForm1;
const
RECIEVETIMEOUT =5000;
type
TCommBlock = record
SenderName,
Msg :string[100];
end;
implementation{$R *.dfm}procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);///此行报错为[Error] Unit1.pas(28): Undeclared /////////////////////////////identifier: 'TIdSocketHandle'
var
Comm:TCommBlock;
begin
AData.ReadBuffer(Comm,AData.Size );
Memo1.Lines.Add(Comm.SenderName+':'+Comm.Msg );
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
idudpclient1.Host:= edit1.Text;
idudpclient1.Port :=StrToInt(edit3.Text );
idudpclient1.ReceiveTimeout :=RECIEVETIMEOUT;
idudpserver1.DefaultPort:=StrToInt(edit4.Text);
idudpserver1.Active:=True;
BitBtn1.Enabled:=True;
end;procedure TForm1.BitBtn2Click(Sender: TObject);
var
Comm:TCommBlock;
begin
Comm.SenderName:= edit2.Text ;
Comm.Msg := edit5.Text ;
Memo1.Lines.Add(Comm.SenderName+':'+Comm.Msg );
idudpclient1.SendBuffer(Comm,sizeof(Comm));
end;end.
回复EM:[email protected],兄弟先谢了!!!
我用的是udpclient,udpserver两个组件,在uses里添加了winsock后,执行报错!!
源程序如上:
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdUDPServer, IdBaseComponent, IdComponent, IdUDPBase,
IdUDPClient, Buttons,WinSock;type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
IdUDPClient1: TIdUDPClient;
IdUDPServer1: TIdUDPServer;
Memo1: TMemo;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations } end;
var
Form1: TForm1;
const
RECIEVETIMEOUT =5000;
type
TCommBlock = record
SenderName,
Msg :string[100];
end;
implementation{$R *.dfm}procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);///此行报错为[Error] Unit1.pas(28): Undeclared /////////////////////////////identifier: 'TIdSocketHandle'
var
Comm:TCommBlock;
begin
AData.ReadBuffer(Comm,AData.Size );
Memo1.Lines.Add(Comm.SenderName+':'+Comm.Msg );
end;procedure TForm1.BitBtn1Click(Sender: TObject);
begin
idudpclient1.Host:= edit1.Text;
idudpclient1.Port :=StrToInt(edit3.Text );
idudpclient1.ReceiveTimeout :=RECIEVETIMEOUT;
idudpserver1.DefaultPort:=StrToInt(edit4.Text);
idudpserver1.Active:=True;
BitBtn1.Enabled:=True;
end;procedure TForm1.BitBtn2Click(Sender: TObject);
var
Comm:TCommBlock;
begin
Comm.SenderName:= edit2.Text ;
Comm.Msg := edit5.Text ;
Memo1.Lines.Add(Comm.SenderName+':'+Comm.Msg );
idudpclient1.SendBuffer(Comm,sizeof(Comm));
end;end.
回复EM:[email protected],兄弟先谢了!!!
但是有的端口设置时报错::
could not bind socket,address and port is used!