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 属性。 如果是WriteableNetworkStream则允许调用Write该方法。true 还可以通过检查可公开访问CanWrite的属性来确定某个NetworkStream项是否可写。

初始化 WriteableNetworkStream 设置该属性。

适用于

另请参阅