我知道这个问题经常被问到,在我在这里发布我的问题之前我已经做了一些搜索,但仍然无法找到我的问题的解决方案。
在Delphi VCL中,我可以识别套接字是否已连接;
if Socket.Connected = True then
但是在Android上的Delphi FMX中,没有这个功能!
我的代码:
Procedure TForm24.SocketConnect;
var
FClientSocket: TSocket;
Buf: TBytes;
begin
//Connect to VCL server
FClientSocket := TSocket.Create(TSocketType.TCP);
FClientSocket.Connect(string.Empty, '192.168.1.155'+#0, string.Empty, 4851);
//if FClientSocket.Connected then
while True do
begin
// Receive the message from the VCL server
SetLength(Buf, 4);
FClientSocket.Receive(Buf, 4);
// Some code here...
end;
end;