Share via


UdpClient.Client 속성

정의

내부 네트워크 Socket을 가져오거나 설정합니다.

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

속성 값

내부 네트워크 Socket입니다.

예제

다음 예제에서는 사용 된 Client 속성입니다. 이 예제에서는 기본 에 대해 브로드캐스트를 사용하도록 설정됩니다 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

설명

UdpClientSocket 네트워크를 통해 데이터를 보내고 받는 데 사용되는 을 만듭니다. 에서 UdpClient 파생되는 클래스는 이 속성을 사용하여 이 Socket를 얻거나 설정할 수 있습니다. 에서 반환 ClientUdpClient 된 기본 을 Socket 사용합니다. 를 사용하여 Client 기본 을 Socket 기존 Socket로 설정할 수도 있습니다. 이 기능은 기존 Socket을 사용하는 단순성을 UdpClient 활용하려는 경우에 유용합니다.

적용 대상

추가 정보