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

속성 값

스트림에 데이터를 쓸 수 있으면 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

설명

속성을 사용 Writeable 하려면 클래스에서 NetworkStream 파생해야 합니다. 가 이 trueNetworkStreamWriteable 메서드에 대한 호출을 Write 허용합니다. 공개적으로 액세스할 수 있는 속성을 확인하여 를 NetworkStream 쓸 수 있는지 여부를 확인할 수도 있습니다 CanWrite .

속성은 Writeable 가 초기화될 때 NetworkStream 설정됩니다.

적용 대상

추가 정보