Problem with BackLog (TCP Queue)..



I'm building a web server and having some issues with the
TCPListener.Start(BackLog). It doesn't seem to do as expected. I'm using
MS Web Stress Tool to test against my web server and when I see 200
connections at once to it, and I'm seeing 2/3 of the sockets as socket
errors.. They never get into my code, so it has to be failing on the
connection side.. Backlog is the only thing I can think could be the
problem. this.svrListener.Start(1024); should be well over enough, but
with no param passed in Start or with 4096, it seems to be exactly the same.

My code goes as follows...
-------------------------------------
//declare listener
private TcpListener svrListener;
//declare port
private Int32 m_lPort = 80; // Select any free port you wish.
Default to 80
//declare host
private String m_szHost = ""; // Select any ip you wish
//declare max kb
private Int32 m_lMaxKBPerSec = 50; // Select max KB per second. Default is
50KB.

//signal.
private static ManualResetEvent clientConnected = new
ManualResetEvent(false);

//Constructor
public CListen(string szHost, Int32 lPort, Int32 lMaxKBPerSec)
{
this.m_lPort = lPort;
this.m_szHost = szHost;
this.m_lMaxKBPerSec = lMaxKBPerSec;
}

//start listener
public void ProcessListener()
{
IPAddress inputDNS_IP;

//setup IP to listen on
if (this.m_szHost.Length == 0)
{
inputDNS_IP = IPAddress.Any;
this.m_szHost = "Any";
}
else
inputDNS_IP = Dns.GetHostEntry(this.m_szHost).AddressList[0];

//log it

try
{
//set to listen on specific IP:port
this.svrListener = new TcpListener(inputDNS_IP, this.m_lPort);
//setup timeouts..
this.svrListener.Server.ReceiveTimeout = 30000;
this.svrListener.Server.SendTimeout = 30000;
//start with a backlog "TCP/IP Queue" of 1024
this.svrListener.Start(1024);
}
catch (SocketException e)
{
//log it
}

while (true)
{
// Set the event to nonsignaled state.
clientConnected.Reset();
// Accept the connection.
// BeginAcceptSocket() creates the accepted socket.
this.svrListener.BeginAcceptSocket(new
AsyncCallback(DoAcceptSocketCallback), this.svrListener);

//log it

// Wait until a connection is made and processed before
// continuing.
clientConnected.WaitOne();

//verify service isn't asking for this DLL to stop.
if (MyWebServer.StopStatus)
break;
}

//this will allow a browser to finish downloading what
//files they are downloading, while not allowing any
//new connections.
while (MyWebServer.CurrentConnection > 0)
Thread.Sleep(1000);
}

// Process the client connection.
public void DoAcceptSocketCallback(IAsyncResult ar)
{
//log client connecting

//Get the listener that handles the client request.
TcpListener listener = (TcpListener)ar.AsyncState;

//End the operation and display the received data on the
//console.
Socket sckConnection = listener.EndAcceptSocket(ar);

//Signal the calling thread to continue, connection info received..
clientConnected.Set();

//increment counter, if fail then too many connections
if (!MyWebServer.AddConnection())
{
//log it

//send message to browser, too many connections
return;
}

//log it accepting

//set vars for Socket Class
CSocket socket = new CSocket(sckConnection, this.m_szHost, this.m_lPort,
this.m_lMaxKBPerSec);

//start the thread
Thread th = new Thread(new ThreadStart(socket.Process));
th.Start();

//log thread created
}


.



Relevant Pages

  • Re: Need Help with IOCP
    ... In my proxy, I accept connections, connect to a web server, make a request. ... The outgoing socket is closed by the web server. ... close the connection to the web browser or it will sit there indefinitely ... The TCP ACK stuff is what the packet sniffer found, ...
    (microsoft.public.win32.programmer.networks)
  • Winsock control and threads
    ... Basicaly I want a listen socket to listen for incomming connection, ... The listener is one object exposed by the componenet. ... it creates an instance of the ActiveSocket object ...
    (microsoft.public.win32.programmer.networks)
  • Problem with a Socket server program opening/accepting many connections and the GC is running.
    ... listening on port 11000 and ready to take a new connection. ... I created the Listener socket, ... connection to be started by my clients. ... I have read all the GC stuff, and socket stuff. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Network connections use
    ... >Is it possible to find out which listener (exe, service, ISAPI, activeX, ... or program did established connection? ... >Is there any relation between program and open socket (for all opened ... And Chris, posting your email address openly will get you more unwanted email, ...
    (microsoft.public.windowsxp.network_web)
  • Problem with a Socket server Opening/Accepting Many sockets and the GC running.
    ... listening on port 11000 and ready to take a new connection. ... I created the Listener socket, ... THen all is well and my clients can connect for about another 3900 ...
    (microsoft.public.dotnet.languages.csharp)

Loading