NetworkStream.Writeable プロパティ

定義

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

protected:
 property bool Writeable { bool get(); void set(bool value); };
protected bool Writeable { get; set; }
member this.Writeable : bool with get, set
Protected Property Writeable As Boolean

プロパティ値

Boolean

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

次のコード例では、プロパティが CanCommunicate プロパティを Writeable チェックして、書き込み可能かどうかを NetworkStream 確認します。

#using <System.dll>

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

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

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

   property bool CanCommunicate 
   {
      bool get()
      {
         if ( !this->Readable | !this->Writeable )
         {
            return false;
         }
         else
         {
            return true;
         }
      }
   }
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 IsConnected
    {
        get
        {
            return this.Socket.Connected;
        }
    }

    public bool CanCommunicate
    {
        get
        {
            if (!this.Readable | !this.Writeable)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
Public Class MyNetworkStream_Sub_Class
   Inherits NetworkStream
   
   
   Public Sub New(socket As Socket, ownsSocket As Boolean)
      MyBase.New(socket, ownsSocket)
   End Sub
   
   ' 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 IsConnected() 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
    ' Do something significant in here

注釈

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

この Writeable プロパティは、初期化時に NetworkStream 設定されます。

適用対象

こちらもご覧ください