次の方法で共有


UdpClient.Active プロパティ

既定のリモート ホストが確立されたかどうかを示す値を取得または設定します。

Protected Property Active As Boolean
[C#]
protected bool Active {get; set;}
[C++]
protected: __property bool get_Active();protected: __property void set_Active(bool);
[JScript]
protected function get Active() : Boolean;protected function set Active(Boolean);

プロパティ値

接続がアクティブな場合は true 。それ以外の場合は false

解説

UdpClient の派生クラスはこのプロパティを使用して、既定のリモート ホストが確立されているかどうかを判断します。既定のリモート ホストは、適切なコンストラクタを使用するか Connect メソッドを呼び出すことによって確立できます。既定のリモート ホストを確立する場合、 Send への呼び出しではリモート ホストを指定できません。

使用例

[Visual Basic, C#, C++] プロテクト プロパティ Active を使用している派生クラスの例を次に示します。この例では、基になる Socket を取得する前に接続がアクティブになっていることを、 MyUdpClientDerivedClass が検証しています。

 
' 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 名前空間 | UdpClient | Connect | Send