UdpClient.Receive メソッドとは? わかりやすく解説

UdpClient.Receive メソッド

リモート ホスト送信した UDP データグラム返します

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

Public Function Receive ( _
    ByRef remoteEP As IPEndPoint _
) As Byte()
Dim instance As UdpClient
Dim remoteEP As IPEndPoint
Dim returnValue As Byte()

returnValue = instance.Receive(remoteEP)
public byte[] Receive (
    ref IPEndPoint remoteEP
)
public:
array<unsigned char>^ Receive (
    IPEndPoint^% remoteEP
)
public byte[] Receive (
    /** @ref */ IPEndPoint remoteEP
)
JScript では、値型引数参照渡しされません。

パラメータ

remoteEP

データ送信元のリモート ホストを表す IPEndPoint。

戻り値
データグラム データ格納する Byte 型の配列

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

Receive メソッドの例を次に示しますReceive メソッドメッセージ受信するまで実行ブロックしますReceive渡されIPEndPoint使用して応答するホストID明らかになります

   'Creates a UdpClient for reading incoming data.
   Dim receivingUdpClient As New
 UdpClient(11000)
   
   'Creates an IPEndPoint to record the IP address and port number of
 the sender. 
   ' The IPEndPoint will allow you to read datagrams sent from any source.
   Dim RemoteIpEndPoint As New
 IPEndPoint(IPAddress.Any, 0)
   Try
      
      ' Blocks until a message returns on this socket from a remote
 host.
      Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint)
      
      Dim returnData As String
 = Encoding.ASCII.GetString(receiveBytes)
      
      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()))
   Catch e As Exception
      Console.WriteLine(e.ToString())
   End Try
End Sub 'MyUdpClientCommunicator
 
 //Creates a UdpClient for reading incoming data.
 UdpClient receivingUdpClient = new UdpClient(11000);

 //Creates an IPEndPoint to record the IP Address and port number of
 the sender. 
// The IPEndPoint will allow you to read datagrams sent from any source.
 IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
 try{

     // Blocks until a message returns on this socket from a remote
 host.
     Byte[] receiveBytes = receivingUdpClient.Receive(ref RemoteIpEndPoint); 

     string returnData = Encoding.ASCII.GetString(receiveBytes);
 
     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());
 }
 catch ( Exception e ){
     Console.WriteLine(e.ToString()); 
 }
 
//Creates a UdpClient for reading incoming data.
UdpClient^ receivingUdpClient = gcnew UdpClient( 11000 );

//Creates an IPEndPoint to record the IP Address and port number of
 the sender. 
// The IPEndPoint will allow you to read datagrams sent from any source.
IPEndPoint^ RemoteIpEndPoint = gcnew IPEndPoint( IPAddress::Any,0 );
try
{
   // Blocks until a message returns on this socket from a remote host.
   array<Byte>^receiveBytes = receivingUdpClient->Receive(  RemoteIpEndPoint
 );

   String^ returnData = Encoding::ASCII->GetString( receiveBytes );

   Console::WriteLine( "This is the message you received {0}", returnData
 );
   Console::WriteLine( "This message was sent from {0} on their port number
 {1}",
      RemoteIpEndPoint->Address, RemoteIpEndPoint->Port );
}
catch ( Exception^ e ) 
{
   Console::WriteLine( e->ToString() );
}
//Creates a UdpClient for reading incoming data.
UdpClient receivingUdpClient = new UdpClient();

// Creates an IPEndPoint to record the IP Address
// and port number of the sender. 
// The IPEndPoint will allow you to 
// read datagrams sent from any source.
IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
try {
    // Blocks until a message returns on this
    // socket from a remote host.
    ubyte receiveBytes[] = 
        receivingUdpClient.Receive(remoteIpEndPoint);
    String returnData = Encoding.get_ASCII().GetString(receiveBytes);
    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())));
}
catch (System.Exception e) {
    Console.WriteLine(e.ToString());
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からUdpClient.Receive メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からUdpClient.Receive メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からUdpClient.Receive メソッド を検索

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

辞書ショートカット

すべての辞書の索引

「UdpClient.Receive メソッド」の関連用語

UdpClient.Receive メソッドのお隣キーワード
検索ランキング

   

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



UdpClient.Receive メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS