Sockets and Completion Ports

Feb 29 2008 4:25 AM

I'm writing a client-server application and I've got a problem understanding the implementation of Completion Ports.

 

My server code looks something like this;

 

public Socket m_socketListener;
public void StartListening()
{
    try
    {
        //Create the lister
        m_socketListener= new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
        IPEndPoint ep = new IPEndPoint ( IPAddress.Any ,8000);
       
// Bind to IP Address
        m_socketListener.Bind(ep);
        // Start listening
        m_socketListener.Listen(4);
        // Call back for the client connections
        m_socketListener.BeginAccept(new AsyncCallback ( OnConnect ),null);
        cmdListen.Enabled = false;
    }
    catch(SocketException se)
    {
        MessageBox.Show ( se.Message );
    }
}

From what I've read on the net, some people say .NET uses completion ports as an effective thread mamangement model for asynchronous IO. Other people talk about creating a Completion Port object and passing in the handle to a Socket etc. I'm confused over whether .NET automatically uses completion ports or if it's something I have to do myself.

 

In my code above, does BeginAccept automatically use a Completion Port? If so I must be able to specify the thread concurrency for the port, but how?

Thanks in advance for any help.....