UdpClientとは? わかりやすく解説

UdpClient クラス

ユーザー データグラム プロトコル (UDP) ネットワーク サービスを提供します。

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

Public Class UdpClient
    Implements 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());
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
  System.Net.Sockets.UdpClient
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UdpClient メンバ
System.Net.Sockets 名前空間
TcpClient クラス
その他の技術情報
TCP/UDP

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 名前空間

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 内)
構文構文

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

ローカル ポート番号を使用して 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 内)
構文構文

Public Sub New ( _
    hostname As String, _
    port As Integer _
)
Dim hostname As String
Dim port As Integer

Dim instance As New UdpClient(hostname,
 port)
public UdpClient (
    string hostname,
    int port
)
public:
UdpClient (
    String^ hostname, 
    int port
)
public UdpClient (
    String hostname, 
    int port
)
public function UdpClient (
    hostname : String, 
    port : int
)

パラメータ

hostname

接続先のリモート DNS ホスト名。

port

接続先のリモート ポート番号。

例外例外
例外の種類条件

ArgumentNullException

hostname が null 参照 (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

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

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
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。

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

ローカル エンドポイントを使用して 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 メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド 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 から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.IDisposable.Dispose UdpClient によって使用されているすべてのリソースを解放します。
参照参照

関連項目

UdpClient クラス
System.Net.Sockets 名前空間
TcpClient クラス

その他の技術情報

TCP/UDP

UdpClient メンバ

ユーザー データグラム プロトコル (UDP) ネットワーク サービスを提供します。

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 から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイスの実装
  名前 説明
インターフェイスの明示的な実装 System.IDisposable.Dispose UdpClient によって使用されているすべてのリソースを解放します。
参照参照

関連項目

UdpClient クラス
System.Net.Sockets 名前空間
TcpClient クラス

その他の技術情報

TCP/UDP



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「UdpClient」の関連用語

UdpClientのお隣キーワード
検索ランキング

   

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



UdpClientのページの著作権

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

©2026 GRAS Group, Inc.RSS