Share via


NetworkStream.Socket 속성

정의

내부 Socket를 가져옵니다.

public:
 property System::Net::Sockets::Socket ^ Socket { System::Net::Sockets::Socket ^ get(); };
protected:
 property System::Net::Sockets::Socket ^ Socket { System::Net::Sockets::Socket ^ get(); };
public System.Net.Sockets.Socket Socket { get; }
protected System.Net.Sockets.Socket Socket { get; }
member this.Socket : System.Net.Sockets.Socket
Public ReadOnly Property Socket As Socket
Protected ReadOnly Property Socket As Socket

속성 값

내부 네트워크 연결을 나타내는 Socket입니다.

예제

다음 코드 예제에서는 기본을 검색하여 Socket 활성 연결을 확인합니다.

#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

설명

에서 NetworkStream 파생되는 클래스는 이 속성을 사용하여 기본 을 Socket가져올 수 있습니다. 제공된 Socket 것 이상으로 액세스해야 하는 경우 속성에서 Socket 반환된 기본 을 NetworkStream 사용합니다.

참고

이 속성은 이 클래스 또는 파생 클래스를 통해서만 액세스할 수 있습니다.

적용 대상