[SOLVED] check that a intra net server listens to a TCP socket lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- guest58172 · 2016-02-08 14:32 Under windows I have to wait until a local server starts to listen to a particular TCP port. To do so: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function checkSocket: boolean;var  prt: word = 9166;  cli: TInetSocket = nil;begin  sleep(100); // because this proc is looped  result := false;  try try    cli := TInetSocket.Create('localhost', prt);  except    // fail to connect error interpreted as "the server occupies the port"    result := true;  end;  finally    if assigned(cli) then    cli.Free;  end;end; It seems to work however once it returns true, the server fails to create its connection to the socket because it looks like my checker blocks the port. What's the proper way to check if a port is available or not ? ---------------------------------------------------------------------- balazsszekely · 2016-02-08 15:03 Run with TProcess "netstat -a" then parse the result. ---------------------------------------------------------------------- guest58172 · 2016-02-08 15:07 Yeah, this is what I gonna do. I'll wait a bit before considering this Q as solved to see if anyone has a solution using a socket, which would be cleaner. ---------------------------------------------------------------------- balazsszekely · 2016-02-08 15:28 Maybe this helps: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i cli.SocketOptions:= cli.SocketOptions - [soKeepAlive];Alternatively you could use the closesocket api(https://msdn.microsoft.com/en- us/library/windows/desktop/ms737582%28v=vs.85%29.aspx).