NetworkStream.Socket Property
.NET Framework 4
Gets the underlying Socket.
Assembly: System (in System.dll)
Classes deriving from NetworkStream can use this property to get the underlying Socket. Use the underlying Socket returned from the Socket property if you require access beyond that which NetworkStream provides.
Note
|
|---|
|
This property is accessible only through this class or a derived class. |
The following code example retrieves the underlying Socket to verify an active connection.
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; } } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note