UdpClient クラスの新しいインスタンスを初期化し、指定したローカル エンドポイントにバインドします。
名前空間: System.Net.Sockets
アセンブリ: System (system.dll 内)
構文
'宣言
Public Sub New ( _
localEP As IPEndPoint _
)
'使用
Dim localEP As IPEndPoint
Dim instance As New UdpClient(localEP)
public UdpClient (
IPEndPoint localEP
)
public:
UdpClient (
IPEndPoint^ localEP
)
public UdpClient (
IPEndPoint localEP
)
public function UdpClient (
localEP : IPEndPoint
)
パラメータ
- localEP
UDP 接続のバインド先のローカル エンドポイントを表す IPEndPoint。
例外
例外の種類 | 条件 |
---|---|
localEP が null 参照 (Visual Basic では Nothing) です。 |
|
ソケットへのアクセス中にエラーが発生しました。詳細については「解説」を参照してください。 |
解説
このコンストラクタは、新しい 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0
参照
関連項目
UdpClient クラス
UdpClient メンバ
System.Net.Sockets 名前空間
IPEndPoint クラス