NetworkStream::Socket Property

 

Gets the underlying Socket.

Namespace:   System.Net.Sockets
Assembly:  System (in System.dll)

protected:
property Socket^ Socket {
	Socket^ get();
}

Property Value

Type: System.Net.Sockets::Socket^

A Socket that represents the underlying network connection.

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.

System_CAPS_noteNote

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.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;
         }
      }
   }

.NET Framework
Available since 1.1
Return to top
Show: