A caller higher in the call stack does not have permission for the requested operation.

Remarks

If you are using a connection-oriented protocol, the BeginConnect method starts an asynchronous request for a connection to the remoteEP parameter. If you are using a connectionless protocol, BeginConnect establishes a default remote host. Connecting or setting the default remote host asynchronously gives you the ability to send and receive data within a separate execution thread.

You can create acallback method that implements the AsyncCallback delegate and pass its name to the BeginConnect method. At the very minimum, you must pass the Socket to BeginConnect through the state parameter. If your callback needs more information, you can create a small class to hold the Socket, and the other required information. Pass an instance of this class to the BeginConnect method through the state parameter.

Your callback method should implement the EndConnect method. When your application calls BeginConnect, the system will use a separate thread to execute the specified callback method, and will block on EndConnect until the Socket connects successfully or throws an exception. If you want the original thread to block after you call the BeginConnect method, use WaitOne. Call Set in the callback method when you want the original thread to continue executing. For additional information on writing callback methods see Callback Sample.

If you are using a connectionless protocol such as UDP, you do not have to call BeginConnect before sending and receiving data. You can use BeginSendTo and BeginReceiveFrom to communicate with a remote host. If you do call BeginConnect, any datagrams that arrive from an address other than the specified default will be discarded. If you wish to set your default remote host to a broadcast address, you must first call SetSocketOption and set Broadcast to true. If you cannot, BeginConnect will throw a SocketException.

If you are using a connection-oriented protocol and do not call Bind before calling BeginConnect, the underlying service provider will assign the most appropriate local network address and port number. If you are using a connectionless protocol, the service provider will not assign a local network address and port number until you call the BeginSend or ReceiveFrom method. If you want to change the default remote host, call the BeginConnect method again with the desired endpoint.

Note If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Socket Version 2 API error code documentation in MSDN for a detailed description of the error.