NetworkStream.Socket Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém o subjacente 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
Valor de Propriedade
A Socket que representa a ligação de rede subjacente.
Exemplos
O exemplo de código seguinte recupera o subjacente Socket para verificar uma ligação ativa.
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
Observações
Classes derivadas de NetworkStream podem usar esta propriedade para obter o subjacente Socket. Use o subjacente Socket devolvido da Socket propriedade se precisar de acesso para além do que NetworkStream fornece.
Note
Esta propriedade só é acessível através desta classe ou de uma classe derivada.