次の方法で共有


UdpClient コンストラクタ (Int32)

UdpClient クラスの新しいインスタンスを初期化し、指定したローカル ポート番号にバインドします。

名前空間: System.Net.Sockets
アセンブリ: System (system.dll 内)

構文

'宣言
Public Sub New ( _
    port As Integer _
)
'使用
Dim port As Integer

Dim instance As New UdpClient(port)
public UdpClient (
    int port
)
public:
UdpClient (
    int port
)
public UdpClient (
    int port
)
public function UdpClient (
    port : int
)

パラメータ

  • port
    通信を開始するローカル ポート番号。

例外

例外の種類 条件

ArgumentOutOfRangeException

port パラメータが MaxPort より大きい値か MinPort より小さい値です。

SocketException

ソケットへのアクセス中にエラーが発生しました。詳細については「解説」を参照してください。

解説

このコンストラクタは、基になる Socket を作成し、通信を開始するポート番号にバインドします。このコンストラクタは、ローカル ポート番号を設定する場合にだけ使用します。ローカル IP アドレスは、基になるサービス プロバイダによって割り当てられます。コンストラクタに 0 を渡すと、基になるサービス プロバイダによってポート番号が割り当てられます。

注意

SocketException が発生した場合は、SocketException.ErrorCode を使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認できます。これは MSDN から入手できます。

このコンストラクタは、IPv4 アドレス形式でだけ使用できます。

使用例

ローカル ポート番号を使用して 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());
  }
//Creates an instance of the UdpClient class to listen on
// the default interface using a particular port.
try
{
   UdpClient^ udpClient = gcnew UdpClient( 11000 );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}
// Creates an instance of the UdpClient class to listen on
// the default interface using a particular port.
try {
    UdpClient udpClient = new UdpClient(11000);
}
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 名前空間