因为我用的是D7,找不到TClientSocket,所以TClientSocket是动态生成的,并设置Port为1234,
当我打开客户端(服务器是关闭的)设置好要发送的文件和TClientSocket的Host(Host值为127.0.0.1,即是自动的IP地址,因为我只有一台计算机),执行后出现异步端口错误,
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ScktComp, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
ClientSocket1: TClientSocket;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ClientSocket1.Open;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ClientSocket1:= TClientSocket.Create(self);
ClientSocket1.host:='192.168.4.1';
ClientSocket1.Port:=5656;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ClientSocket1.Destroy;
end;
end.
请大家帮忙解决