我有两个使用 TCPServer 和 TCPClient 组件相互通信的应用程序。服务器以隐藏模式启动:Application.ShowMainForm: = false;
只是系统托盘上的一个图标与用户交互。运行服务器后,如果我运行客户端并连接到服务器,则会冻结,但如果我将服务器属性更改Application.ShowMainForm
为true ,则 一切正常。这是我正在使用的代码:
客户端应用:
procedure TFormCliente.FormCreate(Sender: TObject);
begin
try
cliente.Connect;
except
hint1.ActivateHint(FormCliente,'Error.' + #13 +
'Verify if server is running','VCall',5000); //hint1 is a Jed component
end;
end;
服务器应用程序:
[...]
private
FConexoes: TList;
[...]
type
PClient = ^TClient;
TClient = record
PeerIP : string[15]; { Client IP address }
HostName : String[40]; { Hostname }
Connected, { Time of connect }
LastAction : TDateTime; { Time of last transaction }
AContext : Pointer; { Pointer to thread }
end;
[...]
procedure TfrmServer.FormCreate(Sender: TObject);
begin
FConexoes := TList.Create;
end;
procedure TFrmServer.FormDestroy(Sender: TObject);
begin
FConexoes.Free;
end;
procedure TFrmServer.IdTCPServer1Connect(AContext: TIdContext);
var
NewClient: PClient;
begin
GetMem(NewClient, SizeOf(TClient));
NewClient.PeerIP := AContext.Connection.Socket.Binding.PeerIP;
NewClient.HostName := GStack.HostByAddress(NewClient.PeerIP);
NewClient.Connected := Now;
NewClient.LastAction := NewClient.Connected;
NewClient.AContext := AContext;
AContext.Data := TObject(NewClient);
ListView1.Items.Add.Caption:=NewClient.HostName;
end;
如果服务器表单可见,则将客户端主机名添加到列表视图中,但如果服务器表单不可见,则运行 cliente 并连接,服务器将冻结,直到我终止客户端进程。谁能帮我?