UdpClient.Client Property

Definition

Gets or sets the underlying network Socket.

C#
public System.Net.Sockets.Socket Client { get; set; }
C#
protected System.Net.Sockets.Socket Client { get; set; }

Property Value

The underlying Network Socket.

Examples

The following example demonstrates the use of the Client property. In this example, broadcasting is enabled for the underlying Socket.

C#
public static void Main(string[] args)
{
    if (args.Length < 1)
    {
        Console.WriteLine("you must specify a port number!");
        return;
    }

    UdpClient uClient = new UdpClient(Convert.ToInt32(args[0]));
    Socket uSocket = uClient.Client;

    // use the underlying socket to enable broadcast.
    uSocket.SetSocketOption(SocketOptionLevel.Socket,
                  SocketOptionName.Broadcast, 1);
}

Remarks

UdpClient creates a Socket used to send and receive data over a network. Classes deriving from UdpClient can use this property to get or set this Socket. Use the underlying Socket returned from Client if you require access beyond that which UdpClient provides. You can also use Client to set the underlying Socket to an existing Socket. This is useful if you want to take advantage of the simplicity of UdpClient using a pre-existing Socket.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

See also