1

i have tool that is using proxies to send http requests.

I need help with limiting http requests per second.

Currently i'm using following code, but i know this is wrong method.

So my question is how i can limit maximum 300 connections per second and queue threads that executed method while limit?

Using xNet:

        static private string generateToken(ProxyType proxyType, string proxy)
    {
        string tokenResponse = null;
        try
        {
            WaitForConnection();

            using (var request = new HttpRequest())
            {
                request.AllowAutoRedirect = true;
                request.ConnectTimeout = 5000;
                request.Reconnect = false;
                request.ReconnectDelay = 5000;
                request.ReconnectLimit = 1;
                request.Proxy = Socks5ProxyClient.Parse(proxy);


                HttpResponse httpWebRequestresponse = request.Get("http://example.com");

                tokenResponse = httpWebRequestresponse.ToString();
            }

        }
        finally
        {
            totalConnections--;
        }
        return tokenResponse;
    }

static void WaitForConnection()
    {
        bool canConnect = false;
        do
        {
            if (totalConnections <= maxconnectionsNum)
            {
                canConnect = true;
            }
        } while (canConnect == false);
        totalConnections++;
    }
Jesus IYD
  • 26
  • 4
  • Is it what you look for? [Trying to run multiple HTTP requests in parallel, but being limited by Windows (registry)](http://stackoverflow.com/questions/2960056/trying-to-run-multiple-http-requests-in-parallel-but-being-limited-by-windows) – huse.ckr Jan 02 '17 at 06:24
  • No, i need connections per seconds, not concurrent connections... – Jesus IYD Jan 02 '17 at 07:07

0 Answers0