NetworkStream.Readable Egenskap

Definition

Hämtar eller anger ett värde som anger om kan NetworkStream läsas.

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

Egenskapsvärde

trueför att ange att NetworkStream kan läsas, annars . false Standardvärdet är true.

Exempel

I följande kodexempel CanCommunicate kontrollerar Readable egenskapen egenskapen för att avgöra om är NetworkStream läsbar.

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

Kommentarer

Du måste härleda från NetworkStream klassen för att använda Readable egenskapen. Om Readable är true, NetworkStream tillåter anrop till Read metoden. Du kan också avgöra om en NetworkStream är läsbar genom att kontrollera den offentligt tillgängliga CanRead egenskapen.

Egenskapen Readable anges när den NetworkStream initieras.

Gäller för

Se även