UdpClient コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > UdpClient コンストラクタの意味・解説 

UdpClient コンストラクタ (Int32, AddressFamily)

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

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

Public Sub New ( _
    port As Integer, _
    family As AddressFamily _
)
Dim port As Integer
Dim family As AddressFamily

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

パラメータ

port

受信接続試行待機するポート

family

ソケットアドレッシング スキーム指定する AddressFamily 値の 1 つ

例外例外
例外種類条件

ArgumentException

family が InterNetwork または InterNetworkV6 ではありません。

ArgumentOutOfRangeException

port が MaxPort より大きい値か、MinPort より小さい値です。

SocketException

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

解説解説
使用例使用例

マルチキャスト グループ使用する 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);
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UdpClient クラス
UdpClient メンバ
System.Net.Sockets 名前空間

UdpClient コンストラクタ (Int32)

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

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

例外例外
例外種類条件

ArgumentOutOfRangeException

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

SocketException

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

解説解説
使用例使用例

ローカル ポート番号使用して 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());
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UdpClient クラス
UdpClient メンバ
System.Net.Sockets 名前空間

UdpClient コンストラクタ (String, Int32)

UdpClient クラス新しインスタンス初期化し既定リモート ホスト確立します。

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

例外例外
例外種類条件

ArgumentNullException

hostnamenull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

port が MinPort と MaxPort の間の値ではありません。

SocketException

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

解説解説
使用例使用例

ホスト名ポート番号使用して 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());
}
//Creates an instance of the UdpClient class with a remote host name
 and a port number.
try
{
   UdpClient^ udpClient = gcnew UdpClient( "www.contoso.com",11000 );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}
    // 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 (System.Exception e) {
        Console.WriteLine(e.ToString());
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UdpClient クラス
UdpClient メンバ
System.Net.Sockets 名前空間
Send
Connect

UdpClient コンストラクタ (AddressFamily)

UdpClient クラス新しインスタンス初期化します。

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

Public Sub New ( _
    family As AddressFamily _
)
Dim family As AddressFamily

Dim instance As New UdpClient(family)
public UdpClient (
    AddressFamily family
)
public:
UdpClient (
    AddressFamily family
)
public UdpClient (
    AddressFamily family
)
public function UdpClient (
    family : AddressFamily
)

パラメータ

family

ソケットアドレッシング スキーム指定する AddressFamily 値の 1 つ

例外例外
例外種類条件

ArgumentException

family が InterNetwork または InterNetworkV6 ではありません。

SocketException

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

解説解説

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)マルチキャスト グループへの参加には適していません。ソケット バインディング実行しないからです。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UdpClient クラス
UdpClient メンバ
System.Net.Sockets 名前空間

UdpClient コンストラクタ (IPEndPoint)

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。

例外例外
例外種類条件

ArgumentNullException

localEPnull 参照 (Visual Basic では Nothing) です。

SocketException

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

解説解説
使用例使用例

ローカル エンドポイント使用して 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());
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UdpClient クラス
UdpClient メンバ
System.Net.Sockets 名前空間
IPEndPoint クラス

UdpClient コンストラクタ


UdpClient コンストラクタ ()

UdpClient クラス新しインスタンス初期化します。

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

例外例外
解説解説
使用例使用例

既定コンストラクタ使用して 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();
//Creates an instance of the UdpClient class using the default constructor.
UdpClient^ udpClient = gcnew UdpClient;
    // Creates an instance of the UdpClient
    // class using the default constructor.
    UdpClient udpClient = new UdpClient();
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UdpClient クラス
UdpClient メンバ
System.Net.Sockets 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「UdpClient コンストラクタ」の関連用語

UdpClient コンストラクタのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



UdpClient コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS