Ver Mensaje Individual
  #8  
Antiguo 20-10-2014
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.734
Reputación: 20
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
Puedes ver esta conversación.
Por un lado dicen que WSACleanup cierra todos las conexiónes, pero que también puedes hacer
Código Delphi [-]
CloseSocket(sock);
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;      //which server to test
      LTcpClient.Port := APort;         //which port to test
      LTcpClient.ConnectTimeout := 200; //assume a port to be closed if it does not respond within 200ms (some ports will immediately reject, others are using a "stealth" mechnism)
      LTcpClient.Connect;               //try to connect
      result := true;                   //port is open
    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;
Responder Con Cita