Detect port on remote machine on local network [SOLVED] lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- new2linux · 2014-07-14 18:27 I have a function (below) to probe another machine on the local network. The problem is that when the port is closed, it times out after a (much too) long time. How to do better? function IsPortOpen(   ip: string; port: integer): boolean; begin   result := false;   with {synapse}blcksocket.TTCPBlockSocket.create do try     Connect(ip, IntToStr(port));     result := LastError = 0;   finally     Free;   end; end; *) TTCPBlockSocket is from the Synapse library. **) Maybe this isn't a good way to probe for a port. ---------------------------------------------------------------------- marcov · 2014-07-15 09:15 Port scanners usually have two modes, the socket level (like you use) for compatibility, but all you can do is wait and tweak the timeout of the component. The other mode uses raw socket access (SYN?) and thus usually requires administrative permissions. On Windows it might even need a packet filter driver installed. That is not readily prepared in TCP/IP socket suites, so you will have to code your own ---------------------------------------------------------------------- rvk · 2014-07-15 10:03 Quote from: marcov on July 15, 2014, 11:15:04 am... but all you can do is wait and tweak the timeout of the component.Yep. According to this "Timeout for Connect is hardcoded in communication stack of your operating system". So using non-blocking mode would be a possible way to go. But according this it should already be implemented in Synapse. (at least in the SVN version, see here for the ConnectionTimeout property in the connect-function). Did you try the SVN-version? In that case you could just add a "ConnectionTimeout := xxx;" just before the Connect-call. ---------------------------------------------------------------------- new2linux · 2014-07-15 12:33 Two high quality replies, thank you! My goal for today was to investigate non-blocking mode and otherwise use a dozen of threads. I'm glad that was shot down. Indeed I found the new Connect() code and it was already in Synapse. My function becomes: function IsPortOpen(   ip: string; port: integer): boolean; begin   result := false;   with {synapse}blcksocket.TTCPBlockSocket.create do try     //-----------insert -----------     ConnectionTimeout := 500;     //-----------------------------     Connect(ip, IntToStr(port));     result := LastError = 0;   finally     Free;   end; end; My app saved *) Synapse versions? The most recent download says "Release 39, 2009-10-08", which doesn't inspire much confidence. They'd better do a dummy release ; ) ---------------------------------------------------------------------- BigChimp · 2014-07-15 12:50 Quote from: new2linux on July 15, 2014, 02:33:21 pm*) Synapse versions? The most recent download says "Release 39, 2009-10-08", which doesn't inspire much confidence. They'd better do a dummy release ; ) Strange. Where did you see that download? Have a look at 1. The Synapse homepage: http://synapse.ararat.cz/doku.php Quote2012-04-24 New Synapse release 40!2. As mentioned, you can also try the svn trunk version. In my (limited) experience very stable and useful fixes added: http://synapse.ararat.cz/doku.php/download ---------------------------------------------------------------------- new2linux · 2014-07-15 22:46 Quote from: BigChimp on July 15, 2014, 02:50:47 pmQuote from: new2linux on July 15, 2014, 02:33:21 pm*) Synapse versions? The most recent download says "Release 39, 2009-10-08", which doesn't inspire much confidence. They'd better do a dummy release ; ) Strange. Where did you see that download? Have a look at 1. The Synapse homepage: http://synapse.ararat.cz/doku.php Quote2012-04-24 New Synapse release 40!2. As mentioned, you can also try the svn trunk version. In my (limited) experience very stable and useful fixes added: http://synapse.ararat.cz/doku.php/download Indeed. I searched to get the latest Synapse and found:   http://sourceforge.net/projects/synalist/ Which is version 39 and does NOT have the fix. It turns out I already had the fix in my libs because I downloaded the AWS package by Marcos Douglas which included Synapse:   https://github.com/mdbs99/aws As you say, the latest Synapse is to be found at:   http://synapse.ararat.cz/doku.php/download What a mess. ---------------------------------------------------------------------- rvk · 2014-07-16 07:43 Stable release #40 from page http://synapse.ararat.cz/doku.php/download is from April 2014 which does not contain the ConnectionTimeout . You'll need at least SVN version #160 (from June 2012) or higher for that. Yeah... the stable version is old... ---------------------------------------------------------------------- BigChimp · 2014-07-17 09:49 Quote from: new2linux on July 16, 2014, 12:46:23 amWhat a mess. I'm sure a friendly note to Lukas (the maintainer) in the Synapse mailing list may help to address this oversight. At least it's a better chance than posting this on an unrelated forum