Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 196337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:45:31+00:00 2026-05-11T16:45:31+00:00

I am connecting to a 3rd party server. I know right now they allow

  • 0

I am connecting to a 3rd party server. I know right now they allow 8 connections from the same remote user. However i dont know if they will raise or lower the connection limit. So i want my app to dynamically find out. How can i do this?

I’m using C#, MSVS 2008

I started a bounty for anyone who can give me working C#. If no one does then i’ll give it to the best answer.

I find this very difficult to do and had a few failed attempts 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:45:32+00:00Added an answer on May 11, 2026 at 4:45 pm

    I will take this bounty good sir. Not exactly sure why you want to do this and why someone allows 8 connections.

    Defined in 1999 (RFC 2616) “clients
    that use persistent connections should
    limit the number of simultaneous
    connections that they maintain to a
    given server. A single-user client
    SHOULD NOT maintain more than 2
    connections with any server or proxy.
    A proxy SHOULD use up to 2*N
    connections to another server or
    proxy, where N is the number of
    simultaneously active users. These
    guidelines are intended to improve
    HTTP response times and avoid
    congestion.” Since developers are
    using AJAX or AJAX-like requests to
    update a Web page the http limits are
    discussed more and more.

    Like the RFC says, I was only able to get 2 open connections to web servers.

    But here’s the code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Threading;
    
    namespace ConnectionTest
    {
        public class RequestCounter
        {
            public int Counter = 0;
            public void Increment()
            {
                Interlocked.Increment(ref Counter);
            }
        }
    
        public class RequestThread
        {
            public AutoResetEvent AsyncWaitHandle { get; private set; }
            public RequestCounter RequestCounter;
            public String Url;
            public HttpWebRequest Request;
            public HttpWebResponse Response;
    
            public RequestThread(AutoResetEvent r, String u, RequestCounter rc)
            {
                Url = u;
                AsyncWaitHandle = r;
                RequestCounter = rc;
            }
    
            public void Close()
            {
                if (Response != null)
                    Response.Close();
    
                if (Request != null)
                    Request.Abort();
            }
        }
    
        public class ConnectionTest
        {
            static void Main()
            {
                string url = "http://www.google.com/";
                int max = GetMaxConnections(25, url);
                Console.WriteLine(String.Format("{0} Max Connections to {1}",max,url));
                Console.ReadLine();
            }
    
            private static int GetMaxConnections(int maxThreads, string url)
            {
                RequestCounter requestCounter = new RequestCounter();
    
                List<RequestThread> threadState = new List<RequestThread>();
                for (int i = 0; i < maxThreads; i++)
                    threadState.Add(new RequestThread(new AutoResetEvent(false), url, requestCounter));
    
                List<Thread> threads = new List<Thread>();
                foreach (RequestThread state in threadState)
                {
                    Thread t = new Thread(StartRequest);
                    t.Start(state);
                    threads.Add(t);
                }
    
                WaitHandle[] handles = (from state in threadState select state.AsyncWaitHandle).ToArray();
                WaitHandle.WaitAll(handles, 5000); // waits seconds
    
                foreach (Thread t in threads)
                    t.Abort();
    
                foreach(RequestThread rs in threadState)
                    rs.Close();
    
                return requestCounter.Counter;
            }
    
            public static void StartRequest(object rt)
            {
                RequestThread state = (RequestThread) rt;
                try
                {
                    state.Request = (HttpWebRequest)WebRequest.Create(state.Url);
                    state.Request.ReadWriteTimeout = 4000; //Waits 4 seconds
    
                    state.Response = (HttpWebResponse)state.Request.GetResponse();
                    if (state.Response.StatusDescription.Equals("OK", StringComparison.InvariantCultureIgnoreCase))
                        state.RequestCounter.Increment();
    
                    //Do not close, or you will free a connection. Close Later
                    //response.Close(); 
                }
                catch (WebException e)
                {
                    //Console.WriteLine("Message:{0}", e.Message);
                    state.Close();
                }
                catch (ThreadAbortException e)
                {
                    //Console.WriteLine("Thread Aborted");
                    state.Close();
                }
                catch(Exception e)
                {
                    //Console.WriteLine("Real Exception");    
                    state.Close();
                }
                finally
                {
                    state.AsyncWaitHandle.Set();
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am connecting to a 3rd party API. They have provided me with a
Well, having a small problem. A 3rd party is connecting to our API, however
Hitting an OutMemoryError connecting to 3rd party server which cannot process requests fast enough.
I've got some C code from a 3rd party vendor (for an embedded platform)
I'm able to call a 3rd party vendor's web service from a Windows form
I'm using a 3rd party library that maintains a TCP connection to a remote
Does anyone know of a 3rd party library that will convert a Microsoft Word
I have a 3rd party program that I run under a specially created user
I have a MySQL database in a 3rd party server. I am trying to
I have a class that unmarshals xml from a 3rd party source (I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.