Puedes ver
esta conversación.
Por un lado dicen que WSACleanup cierra todos las conexiónes, pero que también puedes hacer
Allí proponen también otra solución para comprobar si un puerto está abierto.
Código Delphi
[-]
function TForm7.PortIsOpen(const APort: Integer; const AAddress: string):
Boolean;
var
LTcpClient: TIdTCPClient;
begin
LTcpClient := TIdTCPClient.Create(nil);
try
try
LTcpClient.Host := AAddress; LTcpClient.Port := APort; LTcpClient.ConnectTimeout := 200; LTcpClient.Connect; result := true; except
result := false;
end;
finally
freeAndNil(LTcpClient);
end;
end;
procedure TForm7.Button1Click(Sender: TObject);
begin
if PortIsOpen(1234, '127.0.0.1') then
ShowMessage('OPEN')
else
ShowMessage('NOT OPEN');
end;