次の方法で共有


NetworkStream.Readable プロパティ

NetworkStream を読み取ることができるかどうかを示す値を取得または設定します。

Protected Property Readable As Boolean
[C#]
protected bool Readable {get; set;}
[C++]
protected: __property bool get_Readable();protected: __property void set_Readable(bool);
[JScript]
protected function get Readable() : Boolean;protected function set Readable(Boolean);

プロパティ値

NetworkStream を読み取ることができる場合は true 。それ以外の場合は false 。既定値は true です。

解説

Readable プロパティを使用するには、 NetworkStream から派生させる必要があります。 Readabletrue の場合は、 NetworkStreamRead メソッドを呼び出すことができます。また、パブリックにアクセス可能な CanRead プロパティを調べて、 NetworkStream が読み取り可能かどうかを確認することもできます。

Readable プロパティは、 NetworkStream が初期化されたときに設定されます。

使用例

[Visual Basic, C#, C++] NetworkStream が読み取り可能かどうかを Readable プロパティをチェックして判別する架空のプロパティ、 CanCommunicate 、の例を次に示します。

 
Public Class MyNetworkStream_Sub_Class
   Inherits NetworkStream
   
   
   Public Sub New(socket As Socket, ownsSocket As Boolean)
      MyBase.New(socket, ownsSocket)
   End Sub 'New
   
   ' Suppose you wanted a property for determining if Socket is connected. You can use
   ' the protected method 'Socket' to return underlying Socket.
   
   Public ReadOnly Property Connected() As Boolean
      Get
         Return Me.Socket.Connected
      End Get
   End Property
   
   ' You could also use public NetworkStream methods 'CanRead' and 'CanWrite'.
   
   Public ReadOnly Property CanCommunicate() As Boolean
      Get
         If Not Me.Readable Or Not Me.Writeable  Then
            Return False
         Else
            Return True
         End If
      End Get
   End Property
    
   Public Shared Sub DoSomethingSignificant()
   End Sub 'DoSomethingSignificant
    ' Do something significant in here
   

[C#] 
using System;
using System.Net;
using System.Net.Sockets;


public class MyNetworkStream_Sub_Class : NetworkStream
{

    public MyNetworkStream_Sub_Class(Socket socket, bool ownsSocket) :
        base(socket, ownsSocket)
    {
    }
    // You can use the Socket method to examine the underlying Socket.
    public bool Connected
    {
        get
        {
            return this.Socket.Connected;
        } 
    }
 
    public bool CanCommunicate
    {
        get
        {
            if (!this.Readable | !this.Writeable)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }

[C++] 
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;


__gc class MyNetworkStream_Sub_Class : public NetworkStream {
public:
    MyNetworkStream_Sub_Class(System::Net::Sockets::Socket* socket, bool ownsSocket) : NetworkStream(socket, ownsSocket) {}

    // You can use the Socket method to examine the underlying Socket.
    __property bool get_Connected() 
    {
        return this->Socket->Connected;
    }

    __property bool get_CanCommunicate() 
    {
        if (!this->Readable | !this->Writeable) 
        {
            return false;
        } else 
        {
            return true;
        }
    }

[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 ファミリ

参照

NetworkStream クラス | NetworkStream メンバ | System.Net.Sockets 名前空間 | CanRead | CanWrite | Writeable