UdpClient.Client Egenskap

Definition

Hämtar eller anger det underliggande nätverket Socket.

protected:
 property System::Net::Sockets::Socket ^ Client { System::Net::Sockets::Socket ^ get(); void set(System::Net::Sockets::Socket ^ value); };
public:
 property System::Net::Sockets::Socket ^ Client { System::Net::Sockets::Socket ^ get(); void set(System::Net::Sockets::Socket ^ value); };
protected System.Net.Sockets.Socket Client { get; set; }
public System.Net.Sockets.Socket Client { get; set; }
member this.Client : System.Net.Sockets.Socket with get, set
Protected Property Client As Socket
Public Property Client As Socket

Egenskapsvärde

Det underliggande nätverket Socket.

Exempel

I följande exempel visas hur egenskapen används Client . I det här exemplet är sändning aktiverat för den underliggande Socket.

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);
}
' This derived class demonstrates the use of three protected methods belonging to the UdpClient class.
Public Class MyUdpClientDerivedClass
   Inherits UdpClient
   
   Public Sub New()
   End Sub
   
   Public Sub UsingProtectedMethods()
      
      'Uses the protected Active property belonging to the UdpClient base class to determine if a connection is established.
      If Me.Active Then
         ' Calls the protected Client property belonging to the UdpClient base class.
         Dim s As Socket = Me.Client
              'Uses the Socket returned by Client to set an option that is not available using UdpClient.
         s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1)
      End If
   End Sub
End Class

Kommentarer

UdpClient skapar en Socket som används för att skicka och ta emot data över ett nätverk. Klasser som härleds från UdpClient kan använda den här egenskapen för att hämta eller ange den här Socket. Använd den underliggande Socket som returneras från Client om du behöver åtkomst utöver det som UdpClient anges. Du kan också använda Client för att ange den underliggande till Socket en befintlig Socket. Detta är användbart om du vill dra nytta av enkelheten UdpClient i att använda en befintlig Socket.

Gäller för

Se även