A
activexform
Unregistered / Unconfirmed
GUEST, unregistred user!
有这么一个问题 ,在 Socket 中,服务端与客户端分别用 TServerSocket 和 TClientSocket
;因为客户端会在服务端运行前运行,怎样才能做到一旦服务端启动客户端就链接到服务端 ?
-------------------------
我这样做没有效果(服务端启动后客户端不会链接到服务端)
var
b : Boolean ;
procedure TForm1.FormCreate(Sender: TObject);
begin
b := True ;
if ClientSocket1.Active = false then
begin
try
ClientSocket1.Open ;
except
b := False ;
Timer1.Enabled := True ;
end ;
end ;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
bk : Boolean ;
begin
bk := True ;
try
ClientSocket1.Open ;
Caption := 'Ok' ;
except
bk := False ;
end ;
if bk then
begin
b := True ;
Timer1.Enabled := False ;
end ;
end;
procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
var
StrErr: string;
begin
case ErrorEvent of
eeConnect: StrErr := '不能建立连接';
eeDisconnect: StrErr := '连接被关闭';
eeReceive: StrErr := '接收数据出错';
eeSend: StrErr := '发送数据出错';
else
StrErr := '连接出错';
end;
ShowMessage(StrErr);
ErrorCode := 0;
if ClientSocket1.Active then
ClientSocket1.Active := False;
end;
请问应该怎样处理 ? 谢谢您
;因为客户端会在服务端运行前运行,怎样才能做到一旦服务端启动客户端就链接到服务端 ?
-------------------------
我这样做没有效果(服务端启动后客户端不会链接到服务端)
var
b : Boolean ;
procedure TForm1.FormCreate(Sender: TObject);
begin
b := True ;
if ClientSocket1.Active = false then
begin
try
ClientSocket1.Open ;
except
b := False ;
Timer1.Enabled := True ;
end ;
end ;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
bk : Boolean ;
begin
bk := True ;
try
ClientSocket1.Open ;
Caption := 'Ok' ;
except
bk := False ;
end ;
if bk then
begin
b := True ;
Timer1.Enabled := False ;
end ;
end;
procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
var
StrErr: string;
begin
case ErrorEvent of
eeConnect: StrErr := '不能建立连接';
eeDisconnect: StrErr := '连接被关闭';
eeReceive: StrErr := '接收数据出错';
eeSend: StrErr := '发送数据出错';
else
StrErr := '连接出错';
end;
ShowMessage(StrErr);
ErrorCode := 0;
if ClientSocket1.Active then
ClientSocket1.Active := False;
end;
请问应该怎样处理 ? 谢谢您