UdpClient クラス
アセンブリ: System (system.dll 内)

Public Class UdpClient Implements IDisposable
public class UdpClient : IDisposable
public ref class UdpClient : IDisposable
public class UdpClient implements IDisposable
public class UdpClient implements IDisposable

UdpClient クラスは、同期ブロッキング モードのときにコネクションレスの UDP データグラムを送受信するための単純なメソッドを提供します。UDP はコネクションレスのトランスポート プロトコルであるため、データを送受信する前にリモート ホスト接続を確立する必要はありません。ただし、オプションとして次の 2 つのいずれかの方法で既定のリモート ホストを設定できます。
UdpClient が用意している送信メソッドのうちの任意のメソッドを使用して、リモート デバイスにデータを送信できます。Receive メソッドを使用して、リモート ホストからデータを受信します。
![]() |
---|
既定のリモート ホストが既に指定されている場合は、ホスト名または IPEndPoint を使用して Send を呼び出すことはできません。この呼び出しを行った場合は、UdpClient が例外をスローします。 |
また、UdpClient メソッドを使用すると、マルチキャスト データグラムを送受信することもできます。JoinMulticastGroup メソッドを使用して、UdpClient がマルチキャスト グループをサブスクライブするようにします。DropMulticastGroup メソッドは、マルチキャスト グループから UdpClient をアンサブスクライブするときに使用します。

ポート 11000 上のホスト名 www.contoso.com を使用して UdpClient 接続を確立する例を次に示します。2 つの別個のリモート ホスト コンピュータに小さな文字列メッセージが送信されます。Receive メソッドはメッセージを受信するまで実行をブロックします。Receive に渡された IPEndPoint を使用して、応答するホストの ID が明らかになります。
' This constructor arbitrarily assigns the local port number. Dim udpClient As New UdpClient(11000) Try udpClient.Connect("www.contoso.com", 11000) ' Sends a message to the host to which you have connected. Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?") udpClient.Send(sendBytes, sendBytes.Length) ' Sends message to a different host using optional hostname and port parameters. Dim udpClientB As New UdpClient() udpClientB.Send(sendBytes, sendBytes.Length, "AlternateHostMachineName", 11000) ' IPEndPoint object will allow us to read datagrams sent from any source. Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0) ' UdpClient.Receive blocks until a message is received from a remote host. Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint) Dim returnData As String = Encoding.ASCII.GetString(receiveBytes) ' Which one of these two hosts responded? Console.WriteLine(("This is the message you received " + _ returnData.ToString())) Console.WriteLine(("This message was sent from " + _ RemoteIpEndPoint.Address.ToString() + _ " on their port number " + _ RemoteIpEndPoint.Port.ToString())) udpClient.Close() udpClientB.Close() Catch e As Exception Console.WriteLine(e.ToString()) End Try End Sub
// This constructor arbitrarily assigns the local port number. UdpClient udpClient = new UdpClient(11000); try{ udpClient.Connect("www.contoso.com", 11000); // Sends a message to the host to which you have connected. Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there?"); udpClient.Send(sendBytes, sendBytes.Length); // Sends a message to a different host using optional hostname and port parameters. UdpClient udpClientB = new UdpClient(); udpClientB.Send(sendBytes, sendBytes.Length, "AlternateHostMachineName", 11000); //IPEndPoint object will allow us to read datagrams sent from any source. IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); // Blocks until a message returns on this socket from a remote host. Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); string returnData = Encoding.ASCII.GetString(receiveBytes); // Uses the IPEndPoint object to determine which of these two hosts responded. Console.WriteLine("This is the message you received " + returnData.ToString()); Console.WriteLine("This message was sent from " + RemoteIpEndPoint.Address.ToString() + " on their port number " + RemoteIpEndPoint.Port.ToString()); udpClient.Close(); udpClientB.Close(); } catch (Exception e ) { Console.WriteLine(e.ToString()); }
// With this constructor the local port number is arbitrarily assigned. UdpClient^ udpClient = gcnew UdpClient; try { udpClient->Connect( "host.contoso.com", 11000 ); // Send message to the host to which you have connected. array<Byte>^sendBytes = Encoding::ASCII->GetBytes( "Is anybody there?" ); udpClient->Send( sendBytes, sendBytes->Length ); // Send message to a different host using optional hostname and port parameters. UdpClient^ udpClientB = gcnew UdpClient; udpClientB->Send( sendBytes, sendBytes->Length, "AlternateHostMachineName", 11000 ); //IPEndPoint object will allow us to read datagrams sent from any source. IPEndPoint^ RemoteIpEndPoint = gcnew IPEndPoint( IPAddress::Any,0 ); // Block until a message returns on this socket from a remote host. array<Byte>^receiveBytes = udpClient->Receive( RemoteIpEndPoint ); String^ returnData = Encoding::ASCII->GetString( receiveBytes ); // Use the IPEndPoint object to determine which of these two hosts responded. Console::WriteLine( String::Concat( "This is the message you received ", returnData->ToString() ) ); Console::WriteLine( String::Concat( "This message was sent from ", RemoteIpEndPoint->Address->ToString(), " on their port number ", RemoteIpEndPoint->Port.ToString() ) ); udpClient->Close(); udpClientB->Close(); } catch ( Exception^ e ) { Console::WriteLine( e->ToString() ); }
// This constructor arbitrarily assigns the local port number. UdpClient udpClient = new UdpClient(); try { udpClient.Connect("www.contoso.com", 11000); // Sends a message to the host to which you have connected. ubyte sendBytes[] = Encoding.get_ASCII().GetBytes("Is anybody there?"); udpClient.Send(sendBytes, sendBytes.length); // Sends a message to a different host using // optional hostname and port parameters. UdpClient udpClientB = new UdpClient(); udpClientB.Send(sendBytes, sendBytes.length, "AlternateHostMachineName", 11000); // IPEndPoint object will allow us to read // datagrams sent from any source. IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); // Blocks until a message returns on this socket // from a remote host. ubyte receiveBytes[] = udpClient.Receive(remoteIpEndPoint); String returnData = Encoding.get_ASCII().GetString(receiveBytes); // Uses the IPEndPoint object to determine which of // these two hosts responded. Console.WriteLine(("This is the message you received " + returnData.ToString())); Console.WriteLine(("This message was sent from " + remoteIpEndPoint.get_Address().ToString() + " on their port number " + System.Convert.ToString(remoteIpEndPoint.get_Port()))); udpClient.Close(); udpClientB.Close(); } catch (System.Exception e) { Console.WriteLine(e.ToString()); }


System.Net.Sockets.UdpClient


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


UdpClient コンストラクタ ()
アセンブリ: System (system.dll 内)



このコンストラクタは、新しい UdpClient を作成し、基になるサービス プロバイダが最も適切なローカル IPv4 アドレスおよびポート番号を割り当てられるようにします。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode を使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認できます。これは MSDN から入手できます。 |
このコンストラクタはマルチキャスト グループへの参加には適していません。ソケット バインディングを実行しないからです。なお、このコンストラクタは、IPv4 アドレス形式でだけ使用できます。

既定のコンストラクタを使用して UdpClient クラスのインスタンスを作成する方法を次の例に示します。
'Creates an instance of the UdpClient class using the default constructor. Dim udpClient As New UdpClient()
//Creates an instance of the UdpClient class using the default constructor. UdpClient udpClient = new UdpClient();

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


UdpClient コンストラクタ (Int32, AddressFamily)
アセンブリ: System (system.dll 内)



このコンストラクタは、基になる Socket を作成し、通信を開始するポート番号にバインドします。
family パラメータは、リスナが IPv4 (IP Version 4) アドレスと IPv6 (IP Version 6) アドレスのどちらを使用するかを決定します。IPv4 アドレスを使用するには、InterNetwork 値を渡します。IPv6 アドレスを使用するには、InterNetworkV6 値を渡します。その他の値を渡すと、メソッドは ArgumentException をスローします。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode を使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認してください。これは MSDN ライブラリから入手できます。 |

マルチキャスト グループで使用する UDP クライアントを作成する方法を次のコード例に示します。
' Bind and listen on port 2000. This constructor creates a socket ' and binds it to the port on which to receive data. The family ' parameter specifies that this connection uses an IPv6 address. clientOriginator = New UdpClient(2000, AddressFamily.InterNetworkV6) ' Join or create a multicast group. The multicast address ranges ' to use are specified in RFC#2375. You are free to use ' different addresses. ' Transform the string address into the internal format. m_GrpAddr = IPAddress.Parse("FF01::1") ' Display the multicast address used. Console.WriteLine(("Multicast Address: [" + m_GrpAddr.ToString() + "]")) ' Exercise the use of the IPv6MulticastOption. Console.WriteLine("Instantiate IPv6MulticastOption(IPAddress)") ' Instantiate IPv6MulticastOption using one of the ' overloaded constructors. Dim ipv6MulticastOption As New IPv6MulticastOption(m_GrpAddr) ' Store the IPAdress multicast options. Dim group As IPAddress = ipv6MulticastOption.Group Dim interfaceIndex As Long = ipv6MulticastOption.InterfaceIndex ' Display IPv6MulticastOption properties. Console.WriteLine(("IPv6MulticastOption.Group: [" + group.ToString() + "]")) Console.WriteLine(("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex.ToString() + "]")) ' Instantiate IPv6MulticastOption using another ' overloaded constructor. Dim ipv6MulticastOption2 As New IPv6MulticastOption(group, interfaceIndex) ' Store the IPAdress multicast options. group = ipv6MulticastOption2.Group interfaceIndex = ipv6MulticastOption2.InterfaceIndex ' Display the IPv6MulticastOption2 properties. Console.WriteLine(("IPv6MulticastOption.Group: [" + group.ToString() + "]")) Console.WriteLine(("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex.ToString() + "]")) ' Join the specified multicast group using one of the ' JoinMulticastGroup overloaded methods. clientOriginator.JoinMulticastGroup(Fix(interfaceIndex), group) ' Define the endpoint data port. Note that this port number ' must match the ClientTarget UDP port number which is the ' port on which the ClientTarget is receiving data. m_ClientTargetdest = New IPEndPoint(m_GrpAddr, 1000)
// Bind and listen on port 2000. This constructor creates a socket // and binds it to the port on which to receive data. The family // parameter specifies that this connection uses an IPv6 address. clientOriginator = new UdpClient(2000, AddressFamily.InterNetworkV6); // Join or create a multicast group. The multicast address ranges // to use are specified in RFC#2375. You are free to use // different addresses. // Transform the string address into the internal format. m_GrpAddr = IPAddress.Parse("FF01::1"); // Display the multicast address used. Console.WriteLine("Multicast Address: [" + m_GrpAddr.ToString() + "]"); // Exercise the use of the IPv6MulticastOption. Console.WriteLine("Instantiate IPv6MulticastOption(IPAddress)"); // Instantiate IPv6MulticastOption using one of the // overloaded constructors. IPv6MulticastOption ipv6MulticastOption = new IPv6MulticastOption(m_GrpAddr); // Store the IPAdress multicast options. IPAddress group = ipv6MulticastOption.Group; long interfaceIndex = ipv6MulticastOption.InterfaceIndex; // Display IPv6MulticastOption properties. Console.WriteLine("IPv6MulticastOption.Group: [" + group + "]"); Console.WriteLine("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex + "]"); // Instantiate IPv6MulticastOption using another // overloaded constructor. IPv6MulticastOption ipv6MulticastOption2 = new IPv6MulticastOption(group, interfaceIndex); // Store the IPAdress multicast options. group = ipv6MulticastOption2.Group; interfaceIndex = ipv6MulticastOption2.InterfaceIndex; // Display the IPv6MulticastOption2 properties. Console.WriteLine("IPv6MulticastOption.Group: [" + group + "]"); Console.WriteLine("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex + "]"); // Join the specified multicast group using one of the // JoinMulticastGroup overloaded methods. clientOriginator.JoinMulticastGroup((int)interfaceIndex, group); // Define the endpoint data port. Note that this port number // must match the ClientTarget UDP port number which is the // port on which the ClientTarget is receiving data. m_ClientTargetdest = new IPEndPoint(m_GrpAddr, 1000);
// Bind and listen on port 2000. This constructor creates a socket // and binds it to the port on which to receive data. The family // parameter specifies that this connection uses an IPv6 address. clientOriginator = gcnew UdpClient( 2000,AddressFamily::InterNetworkV6 ); // Join or create a multicast group. The multicast address ranges // to use are specified in RFC#2375. You are free to use // different addresses. // Transform the String* address into the internal format. m_GrpAddr = IPAddress::Parse( "FF01::1" ); // Display the multicast address used. Console::WriteLine( "Multicast Address: [ {0}]", m_GrpAddr ); // Exercise the use of the IPv6MulticastOption. Console::WriteLine( "Instantiate IPv6MulticastOption(IPAddress)" ); // Instantiate IPv6MulticastOption using one of the // overloaded constructors. IPv6MulticastOption^ ipv6MulticastOption = gcnew IPv6MulticastOption( m_GrpAddr ); // Store the IPAdress multicast options. IPAddress^ group = ipv6MulticastOption->Group; __int64 interfaceIndex = ipv6MulticastOption->InterfaceIndex; // Display IPv6MulticastOption properties. Console::WriteLine( "IPv6MulticastOption::Group: [ {0}]", group ); Console::WriteLine( "IPv6MulticastOption::InterfaceIndex: [ {0}]", interfaceIndex ); // Instantiate IPv6MulticastOption using another // overloaded constructor. IPv6MulticastOption^ ipv6MulticastOption2 = gcnew IPv6MulticastOption( group,interfaceIndex ); // Store the IPAdress multicast options. group = ipv6MulticastOption2->Group; interfaceIndex = ipv6MulticastOption2->InterfaceIndex; // Display the IPv6MulticastOption2 properties. Console::WriteLine( "IPv6MulticastOption::Group: [ {0} ]", group ); Console::WriteLine( "IPv6MulticastOption::InterfaceIndex: [ {0} ]", interfaceIndex ); // Join the specified multicast group using one of the // JoinMulticastGroup overloaded methods. clientOriginator->JoinMulticastGroup( (int)interfaceIndex, group ); // Define the endpoint data port. Note that this port number // must match the ClientTarget UDP port number which is the // port on which the ClientTarget is receiving data. m_ClientTargetdest = gcnew IPEndPoint( m_GrpAddr,1000 );
// Bind and listen on port 2000. This constructor creates a socket // and binds it to the port on which to receive data. The family // parameter specifies that this connection uses an IPv6 address. clientOriginator = new UdpClient(2000, AddressFamily.InterNetworkV6); // Join or create a multicast group. The multicast address ranges // to use are specified in RFC#2375. You are free to use // different addresses. // Transform the string address into the internal format. m_GrpAddr = IPAddress.Parse("FF01::1"); // Display the multicast address used. Console.WriteLine( ("Multicast Address: [" + m_GrpAddr.ToString() + "]")); // Exercise the use of the IPv6MulticastOption. Console.WriteLine("Instantiate IPv6MulticastOption(IPAddress)"); // Instantiate IPv6MulticastOption using one of the // overloaded constructors. IPv6MulticastOption ipv6MulticastOption = new IPv6MulticastOption(m_GrpAddr); // Store the IPAdress multicast options. IPAddress group = ipv6MulticastOption.get_Group(); long interfaceIndex = ipv6MulticastOption.get_InterfaceIndex(); // Display IPv6MulticastOption properties. Console.WriteLine(("IPv6MulticastOption.Group: [" + group + "]")); Console.WriteLine( ("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex + "]")); // Instantiate IPv6MulticastOption using another // overloaded constructor. IPv6MulticastOption ipv6MulticastOption2 = new IPv6MulticastOption(group, interfaceIndex); // Store the IPAdress multicast options. group = ipv6MulticastOption2.get_Group(); interfaceIndex = ipv6MulticastOption2.get_InterfaceIndex(); // Display the IPv6MulticastOption2 properties. Console.WriteLine(("IPv6MulticastOption.Group: [" + group + "]")); Console.WriteLine( ("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex + "]")); // Join the specified multicast group using one of the // JoinMulticastGroup overloaded methods. clientOriginator.JoinMulticastGroup((int)(interfaceIndex), group); // Define the endpoint data port. Note that this port number // must match the ClientTarget UDP port number which is the // port on which the ClientTarget is receiving data. m_ClientTargetdest = new IPEndPoint(m_GrpAddr, 1000);

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


UdpClient コンストラクタ (Int32)
アセンブリ: System (system.dll 内)



このコンストラクタは、基になる Socket を作成し、通信を開始するポート番号にバインドします。このコンストラクタは、ローカル ポート番号を設定する場合にだけ使用します。ローカル IP アドレスは、基になるサービス プロバイダによって割り当てられます。コンストラクタに 0 を渡すと、基になるサービス プロバイダによってポート番号が割り当てられます。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode を使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認できます。これは MSDN から入手できます。 |

ローカル ポート番号を使用して UdpClient クラスのインスタンスを作成する方法を次の例に示します。
'Creates an instance of the UdpClient class to listen on 'the default interface using a particular port. Try Dim udpClient As New UdpClient(11000) Catch e As Exception Console.WriteLine(e.ToString()) End Try
//Creates an instance of the UdpClient class to listen on // the default interface using a particular port. try{ UdpClient udpClient = new UdpClient(11000); } catch (Exception e ) { Console.WriteLine(e.ToString()); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


UdpClient コンストラクタ (String, Int32)
アセンブリ: System (system.dll 内)



このコンストラクタは新しい UdpClient を初期化し、hostname パラメータおよび port パラメータを使用してリモート ホストを確立します。既定のリモート ホストの確立は省略できます。このコンストラクタを使用すると、Send メソッドへの各呼び出しでリモート ホストを指定する必要がありません。既定のリモート ホストを指定すると、そのホストに限定されるようになります。既定のリモート ホストは、Connect を呼び出すことによっていつでも変更できます。Send メソッドへの呼び出しでリモート ホストを指定する場合は、このコンストラクタを使用しないでください。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode を使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認できます。これは MSDN から入手できます。 |

ホスト名とポート番号を使用して UdpClient クラスのインスタンスを作成する方法を次の例に示します。
'Creates an instance of the UdpClient class with a remote host name and a port number. Try Dim udpClient As New UdpClient("www.contoso.com", 11000) Catch e As Exception Console.WriteLine(e.ToString()) End Try
//Creates an instance of the UdpClient class with a remote host name and a port number. try{ UdpClient udpClient = new UdpClient("www.contoso.com" ,11000); } catch (Exception e ) { Console.WriteLine(e.ToString()); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


UdpClient コンストラクタ (AddressFamily)
アセンブリ: System (system.dll 内)



family パラメータは、リスナが IPv4 (IP Version 4) アドレスと IPv6 (IP Version 6) アドレスのどちらを使用するかを決定します。IPv4 アドレスを使用するには、InterNetwork 値を渡します。IPv6 アドレスを使用するには、InterNetworkV6 値を渡します。その他の値を渡すと、メソッドは ArgumentException をスローします。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode を使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認できます。これは MSDN から入手できます。 |
System.Net.Sockets.UdpClient(AddressFamily) はマルチキャスト グループへの参加には適していません。ソケット バインディングを実行しないからです。

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


UdpClient コンストラクタ (IPEndPoint)
アセンブリ: System (system.dll 内)



このコンストラクタは、新しい UdpClient を作成し、これを localEP パラメータで指定した IPEndPoint にバインドします。このコンストラクタを呼び出す前に、データの送受信を開始する IP アドレスおよびポート番号を使用して IPEndPoint を作成する必要があります。データを送受信するローカル IP アドレスおよびポート番号を指定する必要はありません。指定しない場合は、基になるサービス プロバイダが最も適切なローカル IP アドレスとポート番号を割り当てます。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode を使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認できます。これは MSDN から入手できます。 |

ローカル エンドポイントを使用して UdpClient クラスのインスタンスを作成する方法を次の例に示します。
'Creates an instance of the UdpClient class using a local endpoint. Dim ipAddress As IPAddress = Dns.Resolve(Dns.GetHostName()).AddressList(0) Dim ipLocalEndPoint As New IPEndPoint(ipAddress, 11000) Try Dim udpClient As New UdpClient(ipLocalEndPoint) Catch e As Exception Console.WriteLine(e.ToString()) End Try
//Creates an instance of the UdpClient class using a local endpoint. IPAddress ipAddress = Dns.Resolve(Dns.GetHostName()).AddressList[0]; IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000); try{ UdpClient udpClient = new UdpClient(ipLocalEndPoint); } catch (Exception e ) { Console.WriteLine(e.ToString()); }
//Creates an instance of the UdpClient class using a local endpoint. IPAddress^ ipAddress = Dns::Resolve( Dns::GetHostName() )->AddressList[ 0 ]; IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 ); try { UdpClient^ udpClient = gcnew UdpClient( ipLocalEndPoint ); } catch ( Exception^ e ) { Console::WriteLine( e->ToString() ); }
// Creates an instance of the UdpClient // class using a local endpoint. IPAddress ipAddress = Dns.Resolve(Dns.GetHostName()).get_AddressList()[0]; IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000); try { UdpClient udpClient = new UdpClient(ipLocalEndPoint); } catch (System.Exception e) { Console.WriteLine(e.ToString()); } }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


UdpClient コンストラクタ

名前 | 説明 |
---|---|
UdpClient () | UdpClient クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
UdpClient (AddressFamily) | UdpClient クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
UdpClient (Int32) | UdpClient クラスの新しいインスタンスを初期化し、指定したローカル ポート番号にバインドします。 .NET Compact Framework によってサポートされています。 |
UdpClient (IPEndPoint) | UdpClient クラスの新しいインスタンスを初期化し、指定したローカル エンドポイントにバインドします。 .NET Compact Framework によってサポートされています。 |
UdpClient (Int32, AddressFamily) | UdpClient クラスの新しいインスタンスを初期化し、指定したローカル ポート番号にバインドします。 .NET Compact Framework によってサポートされています。 |
UdpClient (String, Int32) | UdpClient クラスの新しいインスタンスを初期化し、既定のリモート ホストを確立します。 .NET Compact Framework によってサポートされています。 |

UdpClient プロパティ

名前 | 説明 | |
---|---|---|
![]() | Available | 読み取りが可能なネットワークから受信したデータの量を取得します。 |
![]() ![]() | DontFragment | UdpClient でインターネット プロトコル (IP) データグラムの断片化を許可するかどうかを指定する Boolean 値を取得または設定します。 |
![]() | EnableBroadcast | UdpClient がブロードキャスト パケットの送受信を許可するかどうかを指定する Boolean 値を取得または設定します。 |
![]() | ExclusiveAddressUse | UdpClient で 1 つのクライアントだけがポートを使用できるかどうかを指定する Boolean 値を取得または設定します。 |
![]() | MulticastLoopback | 発信マルチキャスト パケットが送信元アプリケーションに配信されるかどうかを指定する Boolean 値を取得または設定します。 |
![]() | Ttl | UdpClient によって送信されたインターネット プロトコル (IP) パケットの有効期間 (TTL) の値を指定する値を取得または設定します。 |


UdpClient メソッド

名前 | 説明 | |
---|---|---|
![]() | BeginReceive | データグラムをリモート ホストから非同期的に受信します。 |
![]() | BeginSend | オーバーロードされます。 データグラムをリモート ホストに非同期的に送信します。 |
![]() | Close | UDP 接続を終了します。 |
![]() | Connect | オーバーロードされます。 既定のリモート ホストを確立します。 |
![]() | DropMulticastGroup | オーバーロードされます。 マルチキャスト グループへの参加を取り消します。 |
![]() | EndReceive | 保留中の非同期受信を終了します。 |
![]() | EndSend | 保留中の非同期送信を終了します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | JoinMulticastGroup | オーバーロードされます。 UdpClient をマルチキャスト グループに追加します。 |
![]() | Receive | リモート ホストが送信した UDP データグラムを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Send | オーバーロードされます。 リモート ホストに UDP データグラムを送信します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Dispose | UdpClient によって使用されているアンマネージ リソースを解放し、オプションでマネージ リソースも解放します。 |
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |


UdpClient メンバ
ユーザー データグラム プロトコル (UDP) ネットワーク サービスを提供します。
UdpClient データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Available | 読み取りが可能なネットワークから受信したデータの量を取得します。 |
![]() ![]() | DontFragment | UdpClient でインターネット プロトコル (IP) データグラムの断片化を許可するかどうかを指定する Boolean 値を取得または設定します。 |
![]() | EnableBroadcast | UdpClient がブロードキャスト パケットの送受信を許可するかどうかを指定する Boolean 値を取得または設定します。 |
![]() | ExclusiveAddressUse | UdpClient で 1 つのクライアントだけがポートを使用できるかどうかを指定する Boolean 値を取得または設定します。 |
![]() | MulticastLoopback | 発信マルチキャスト パケットが送信元アプリケーションに配信されるかどうかを指定する Boolean 値を取得または設定します。 |
![]() | Ttl | UdpClient によって送信されたインターネット プロトコル (IP) パケットの有効期間 (TTL) の値を指定する値を取得または設定します。 |


名前 | 説明 | |
---|---|---|
![]() | BeginReceive | データグラムをリモート ホストから非同期的に受信します。 |
![]() | BeginSend | オーバーロードされます。 データグラムをリモート ホストに非同期的に送信します。 |
![]() | Close | UDP 接続を終了します。 |
![]() | Connect | オーバーロードされます。 既定のリモート ホストを確立します。 |
![]() | DropMulticastGroup | オーバーロードされます。 マルチキャスト グループへの参加を取り消します。 |
![]() | EndReceive | 保留中の非同期受信を終了します。 |
![]() | EndSend | 保留中の非同期送信を終了します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | JoinMulticastGroup | オーバーロードされます。 UdpClient をマルチキャスト グループに追加します。 |
![]() | Receive | リモート ホストが送信した UDP データグラムを返します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Send | オーバーロードされます。 リモート ホストに UDP データグラムを送信します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Dispose | UdpClient によって使用されているアンマネージ リソースを解放し、オプションでマネージ リソースも解放します。 |
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |


- UdpClientのページへのリンク