views:

157

answers:

2

Hi, I am curious where can I find out that AcceptClient as a callback of BeginAcceptSocket needs to have IAsyncResult as a parameter. In the MSDN article there is only mentioned that return value of BeginAcceptSocket is IAsyncresult. But how could I know that it has to be passed to callback? Thanks!

     public server(int port)
    {
        listener = new TcpListener(System.Net.IPAddress.Any, port);
        listener.BeginAcceptSocket(this.AcceptClient,null);

    }
    private void AcceptClient(IAsyncResult ar)
    {
    }
A: 

http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.beginacceptsocket.aspx

The parameters section tells you that the first parameter expects a System.AsyncCallback, which is a delegate that expects an argument of type System.IAsyncResult.

Francis Gagné
But there is not said that AsyncCallback expects IAsyncResult
Mirek
The first parameter of the AsyncCallback delegate is an IAsyncResult.
Jess
A: 

From its documentation, you know that BeginAcceptSocket expects an AsyncCallback as its first parameter, so the next step is to read the documentation for the AsyncCallback delegate, which is itself a type with the following method signature:

public delegate void AsyncCallback(IAsyncResult ar)
Jeff Sternal