Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
true
to indicate that the NetworkStream can be read; otherwise, false
. The default value is true
.
In the following code example, the CanCommunicate
property checks the Readable property to determine if the NetworkStream is readable.
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
You must derive from the NetworkStream class to use the Readable property. If Readable is true
, NetworkStream allows calls to the Read method. You can also determine whether a NetworkStream is readable by checking the publicly accessible CanRead property.
The Readable property is set when the NetworkStream is initialized.
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in