Edit

Share via


UdpClient.EndSend(IAsyncResult) Method

Definition

Ends a pending asynchronous send.

public:
 int EndSend(IAsyncResult ^ asyncResult);
public int EndSend (IAsyncResult asyncResult);
member this.EndSend : IAsyncResult -> int
Public Function EndSend (asyncResult As IAsyncResult) As Integer

Parameters

asyncResult
IAsyncResult

An IAsyncResult object returned by a call to BeginSend.

Returns

If successful, the number of bytes sent to the UdpClient.

Exceptions

asyncResult is null.

asyncResult was not returned by a call to the BeginSend(Byte[], Int32, Int32, SocketFlags, AsyncCallback, Object) method.

EndSend(IAsyncResult) was previously called for the asynchronous read.

An error occurred when attempting to access the underlying socket.

The underlying Socket has been closed.

Examples

The following code example uses BeginSend to complete an asynchronous send of a server request.

public:
    static bool isMessageSent;

    static void SendCallback(IAsyncResult^ asyncResult)
    {
        UdpClient^ udpClient = (UdpClient^)asyncResult->AsyncState;

        Console::WriteLine("number of bytes sent: {0}",
            udpClient->EndSend(asyncResult));
        isMessageSent = true;
    }
public static bool messageSent = false;

public static void SendCallback(IAsyncResult ar)
{
    UdpClient u = (UdpClient)ar.AsyncState;

    Console.WriteLine($"number of bytes sent: {u.EndSend(ar)}");
    messageSent = true;
}

Remarks

This method blocks until the operation is complete.

To perform this operation synchronously, use the Send method.

Applies to