0

I created very simple scanner that will take ip range, get random ip within this range and check if particular port is opened. I use TcpClient

string PORT_CHECK(string IPorNAME, int port)
{
    TcpClient tcpClient = new TcpClient();
    tcpClient.ReceiveTimeout = 10000;
    tcpClient.SendTimeout = 10000;
    try
    {
        tcpClient.Connect(IPorNAME, port);
        return IPorNAME + " : OPEN";
    }
    catch (Exception)
    {
        return IPorNAME + " : CLOSED";
    }
}

I use threadpool

void main()
{
    while (stopper == false)
    {
        ThreadPool.QueueUserWorkItem(new WaitCallback(bGround));
        Thread.Sleep(1);
    }
}

It checks about 10 ips per second, for example a scanner like VNC achieves a speed of about 500 per second, where this major difference comes from, and what to do to speed up my code?

AlphaDelta
  • 2,272
  • 1
  • 18
  • 34

1 Answers1

2

You've set ReceiveTimeout and SendTimeout both to 10000ms (10 seconds). Which means it will wait 10 seconds until it decides it's not there, I'd suggest lowering this number greatly, somewhere around one second (1000) or lower.

AlphaDelta
  • 2,272
  • 1
  • 18
  • 34
  • No, It's not that, I tried with 1000 ms and with 100 ms and I get the same results... – user3192953 Jun 02 '14 at 04:09
  • 1
    I don't get it. How the send/receive timeouts could affect this ? Here the socket is simply connected, nothing is being sent or received. – quantdev Jun 02 '14 at 04:18