NetworkStream.Readable Propriété

Définition

Obtient ou définit une valeur indiquant si NetworkStream peut être lu.Gets or sets a value that indicates whether the NetworkStream can be read.

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

Valeur de propriété

Boolean

true pour indiquer que NetworkStream peut être lu ; sinon, false.true to indicate that the NetworkStream can be read; otherwise, false. La valeur par défaut est true.The default value is true.

Exemples

Dans l’exemple de code suivant, la CanCommunicate propriété vérifie la Readable propriété pour déterminer si le NetworkStream est accessible en lecture.In the following code example, the CanCommunicate property checks the Readable property to determine if the NetworkStream is readable.

#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
   

Remarques

Vous devez dériver de la NetworkStream classe pour utiliser la Readable propriété.You must derive from the NetworkStream class to use the Readable property. Si Readable a true la valeur, NetworkStream autorise les appels à la Read méthode.If Readable is true, NetworkStream allows calls to the Read method. Vous pouvez également déterminer si un NetworkStream est lisible en vérifiant la propriété accessible publiquement CanRead .You can also determine whether a NetworkStream is readable by checking the publicly accessible CanRead property.

La Readable propriété est définie lorsque NetworkStream est initialisé.The Readable property is set when the NetworkStream is initialized.

S’applique à

Voir aussi