次の方法で共有


NetworkStream.Writeable プロパティ

NetworkStream が書き込み可能かどうかを示す値を取得します。

Protected Property Writeable As Boolean
[C#]
protected bool Writeable {get; set;}
[C++]
protected: __property bool get_Writeable();protected: __property void set_Writeable(bool);
[JScript]
protected function get Writeable() : Boolean;protected function set Writeable(Boolean);

プロパティ値

ストリームにデータを書き込むことができる場合は true 。それ以外の場合は false 。既定値は true です。

解説

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

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

使用例

[Visual Basic, C#, C++] NetworkStream が書き込み可能かどうかを Writeable プロパティをチェックして判別する架空のプロパティ、 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 名前空間 | CanWrite | Readable