UdpClient.Client 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 ou define a rede Socketsubjacente .
public:
property System::Net::Sockets::Socket ^ Client { System::Net::Sockets::Socket ^ get(); void set(System::Net::Sockets::Socket ^ value); };
protected:
property System::Net::Sockets::Socket ^ Client { System::Net::Sockets::Socket ^ get(); void set(System::Net::Sockets::Socket ^ value); };
public System.Net.Sockets.Socket Client { get; set; }
protected System.Net.Sockets.Socket Client { get; set; }
member this.Client : System.Net.Sockets.Socket with get, set
Public Property Client As Socket
Protected Property Client As Socket
Valor de Propriedade
A rede Socketsubjacente .
Exemplos
O exemplo seguinte demonstra a utilização da Client propriedade. Neste exemplo, a transmissão está ativada para o subjacente Socket.
public static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("you must specify a port number!");
return;
}
UdpClient uClient = new UdpClient(Convert.ToInt32(args[0]));
Socket uSocket = uClient.Client;
// use the underlying socket to enable broadcast.
uSocket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1);
}
' This derived class demonstrates the use of three protected methods belonging to the UdpClient class.
Public Class MyUdpClientDerivedClass
Inherits UdpClient
Public Sub New()
End Sub
Public Sub UsingProtectedMethods()
'Uses the protected Active property belonging to the UdpClient base class to determine if a connection is established.
If Me.Active Then
' Calls the protected Client property belonging to the UdpClient base class.
Dim s As Socket = Me.Client
'Uses the Socket returned by Client to set an option that is not available using UdpClient.
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1)
End If
End Sub
End Class
Observações
UdpClient cria um Socket usado para enviar e receber dados através de uma rede. Classes derivadas de UdpClient podem usar esta propriedade para obter ou definir este Socket. Use o subjacente Socket retornado se Client precisar de acesso para além do que UdpClient fornece. Também pode usar Client para definir o subjacente Socket como um Socket. Isto é útil se quiser tirar partido da simplicidade de UdpClient usar um Socket.