次の方法で共有


UdpClient.Client プロパティ

基になるネットワーク Socket を取得または設定します。

Protected Property Client As Socket
[C#]
protected Socket Client {get; set;}
[C++]
protected: __property Socket* get_Client();protected: __property void set_Client(Socket*);
[JScript]
protected function get Client() : Socket;protected function set Client(Socket);

プロパティ値

基になるネットワーク Socket

解説

UdpClient は、ネットワーク上でデータを送受信するときに使用する Socket を作成します。 UdpClient の派生クラスはこのプロパティを使用してこの Socket を取得または設定します。 Client が提供する以上のアクセスが必要な場合は、 UdpClient が返した基になる Socket を使用します。 Client を使用して、基になる Socket を既存の Socket に設定することもできます。この方法は、既存の Socket を使用して UdpClient の単純性を利用する場合に役に立つことがあります。

使用例

[Visual Basic, C#, C++] プロテクト プロパティ Client を使用している派生クラスの例を次に示します。この例では、 MyUdpClientDerivedClass が、基になる Socket を取得してブロードキャストを有効にしています。

 
' 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
 


[C#] 
// This derived class demonstrate the use of three protected methods belonging to the UdpClient class.
public class MyUdpClientDerivedClass : UdpClient{

public MyUdpClientDerivedClass() : base(){
}
public 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);
  }
  
}

}

[C++] 
// This derived class demonstrate the use of three protected methods belonging to the UdpClient class.
public __gc 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);
        }
    }
};

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

UdpClient クラス | UdpClient メンバ | System.Net.Sockets 名前空間 | Socket