次の方法で共有


UdpClient.Client プロパティ

定義

基になるネットワーク Socketを取得または設定します。

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

プロパティ値

基になるネットワーク Socket

次の例では、 Client プロパティの使用方法を示します。 この例では、基になる 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

注釈

UdpClient は、ネットワーク経由でデータを送受信するために使用される Socket を作成します。 UdpClientから派生するクラスは、このプロパティを使用して、このSocketを取得または設定できます。 UdpClientが提供するアクセス権を超えるアクセスが必要な場合は、Clientから返される基になるSocketを使用します。 Clientを使用して、基になるSocketを既存のSocketに設定することもできます。 これは、既存のSocketを使用してUdpClientのシンプルさを利用する場合に便利です。

適用対象

こちらもご覧ください