UdpClient.Client Propiedad

Definición

Obtiene o establece el Socket de red subyacente.

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

Valor de propiedad

Socket

Socket de red subyacente.

Ejemplos

En el ejemplo siguiente se muestra el uso de la Client propiedad . En este ejemplo, la difusión está habilitada para el subyacente Socket.

// This derived class demonstrate the use of three protected methods belonging to the UdpClient class.
public ref class MyUdpClientDerivedClass: public UdpClient
{
public:
   MyUdpClientDerivedClass()
      : UdpClient()
   {}

   void UsingProtectedMethods()
   {
      //Uses the protected Active property belonging to the UdpClient base class to determine if a connection is established.
      if ( this->Active )
      {
         //Calls the protected Client property belonging to the UdpClient base class.
         Socket^ s = this->Client;

         //Uses the Socket returned by Client to set an option that is not available using UdpClient.
         s->SetSocketOption( SocketOptionLevel::Socket, SocketOptionName::Broadcast, 1 );
      }
   }
};
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

Comentarios

UdpClient crea un objeto Socket que se usa para enviar y recibir datos a través de una red. Las clases derivadas de UdpClient pueden usar esta propiedad para obtener o establecer este Socket. Use la base Socket devuelta de Client si necesita acceso más allá de lo que UdpClient proporciona. También puede usar Client para establecer el subyacente en Socket un existente Socket. Esto es útil si desea aprovechar la simplicidad de UdpClient usar un elemento preexistente Socket.

Se aplica a

Consulte también