Freigeben über


UdpClient.Client-Eigenschaft

Ruft den zugrunde liegenden Netzwerk-Socket ab oder legt diesen fest.

Namespace: System.Net.Sockets
Assembly: System (in system.dll)

Syntax

'Declaration
Public Property Client As Socket
'Usage
Dim instance As UdpClient
Dim value As Socket

value = instance.Client

instance.Client = value
public Socket Client { get; set; }
public:
property Socket^ Client {
    Socket^ get ();
    void set (Socket^ value);
}
/** @property */
public Socket get_Client ()

/** @property */
public void set_Client (Socket value)
public function get Client () : Socket

public function set Client (value : Socket)

Eigenschaftenwert

Der zugrunde liegende Netzwerk-Socket.

Hinweise

UdpClient erstellt einen Socket zum Senden und Empfangen von Daten in einem Netzwerk. Von UdpClient abgeleitete Klassen können diese Eigenschaft zum Abrufen oder Festlegen dieses Socket verwenden. Verwenden Sie den zugrunde liegenden Socket, der von Client zurückgegeben wurde, wenn Sie mehr als den von UdpClient bereitgestellten Zugriff benötigen. Darüber hinaus können Sie mit Client den zugrunde liegenden Socket auf einen vorhandenen Socket festlegen. Dies empfiehlt sich, wenn Sie mit einem bereits vorhandenen Socket die Vorteile des einfach zu verwendenden UdpClient nutzen möchten.

Beispiel

Im folgenden Beispiel wird die Verwendung der Client-Eigenschaft veranschaulicht. In diesem Beispiel wird die Übertragung für den zugrunde liegenden Socket aktiviert.

' 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 'New
   
   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 'UsingProtectedMethods 
End Class 'MyUdpClientDerivedClass
 
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 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 );
      }
   }
};
// This derived class demonstrate the use of three protected methods
// belonging to the UdpClient class.
public class MyUdpClientDerivedClass extends UdpClient
{
    public MyUdpClientDerivedClass()
    {
        super();
    } //MyUdpClientDerivedClass

    public void UsingProtectedMethods()
    {
        // Uses the protected Active property belonging to the UdpClient base
        // class to determine if a connection is established.
        if (this.get_Active()) {
            //Calls the protected Client property belonging 
            //to the UdpClient base class.
            Socket s = this.get_Client();
            //Uses the Socket returned by Client to set an 
            //option that is not available using UdpClient.
            s.SetSocketOption(SocketOptionLevel.Socket,
                SocketOptionName.Broadcast, 1);
        }
    } //UsingProtectedMethods
} //MyUdpClientDerivedClass

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

UdpClient-Klasse
UdpClient-Member
System.Net.Sockets-Namespace
Socket-Klasse