Delphi7 Indy fast portscan timeout problem

Posted on 2006-05-22
Last Modified: 2010-04-05
I need to write a network scanner which scans a whole subnet to find computers with a specified open port. This is for a multiplayer LAN game, to find the running servers. The scan should be fast with a low timeout. Surprisingly it won't work with the timeout less than 1000ms, which is too high for this task. If I set 10ms for the timeout it scans the first 11 IP addresses then locks up for several seconds then continues for another 11 IP addresses and so on. The extract of the code:

for i:=1 to 255 do begin
 try TCPClient.Connect(10) except on E : Exception do end;
 if TCPClient.Connected then TCPClient.Disconnect;

The problem can be that the scanned IP addresses are  not "alive", but if the timeout is 1000ms no problem occurs.

Thank you in advance!
Question by:gutyka
    LVL 17

    Expert Comment

    I've tried your code, and I do not get the lock up (windows 2000, 256meg ram)
    I have 6 valid pcs in the first 10 ip addresses, and it happily queries them but finds no open port, it then continues and I don't get a lock up
    could it be a resource issue?
    i.e. does a reboot sort it out?
    Do you have a firewall that could be interferring?

    Author Comment

    It turned out to be a WinXP SP2 issue :( On a machine with Windows XP SP1 it works perfectly, after installing Service Pack 2 the problem occurs immediately (no virus scanner, disabled internal firewall, no third-party firewall). Installing Indy 10 won't solve the problem either. So I increase the points because it seems to be a harder problem.

    Author Comment

    I've tried it with TClientSocket and TTCPClient with similar results. I have used non-blocking connections and first a timer for delaying then the OnConnect and OnError events to figure out whether it connects or not. It didn't lock up but after giving back the first results it won't produce any connection. If I wait for about a minute it will run with the same results, so the origin of the problem seems to be identical with the Indy components'. I emphasize that it only happens on WinXP SP2, on SP1 (and for ex. on Win2000) it works fine. I use Delphi 7.

    HEEEELP! :( (now it is for 300 points...)
    LVL 3

    Accepted Solution

    You have to hack the TCPIP.SYS file of windows XP-sp2.. it contains a hardcoded restriction of 10 pending connections i believe..

    You can find a tool that should do the trick on

    Author Comment

    It won't work to ask the players to hack their Windows so the solution is to do the "scanning" part in UDP. Thank you for your help!

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now