Socket.BeginReceive メソッド (ジェネリック IList, SocketFlags, AsyncCallback, Object)
アセンブリ: System (system.dll 内)

<CLSCompliantAttribute(False)> _ Public Function BeginReceive ( _ buffers As IList(Of ArraySegment(Of Byte)), _ socketFlags As SocketFlags, _ callback As AsyncCallback, _ state As Object _ ) As IAsyncResult
Dim instance As Socket Dim buffers As IList(Of ArraySegment(Of Byte)) Dim socketFlags As SocketFlags Dim callback As AsyncCallback Dim state As Object Dim returnValue As IAsyncResult returnValue = instance.BeginReceive(buffers, socketFlags, callback, state)
[CLSCompliantAttribute(false)] public IAsyncResult BeginReceive ( IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback callback, Object state )
[CLSCompliantAttribute(false)] public: IAsyncResult^ BeginReceive ( IList<ArraySegment<unsigned char>>^ buffers, SocketFlags socketFlags, AsyncCallback^ callback, Object^ state )
/** @attribute CLSCompliantAttribute(false) */ public IAsyncResult BeginReceive ( IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback callback, Object state )
CLSCompliantAttribute(false) public function BeginReceive ( buffers : IList<ArraySegment<byte>>, socketFlags : SocketFlags, callback : AsyncCallback, state : Object ) : IAsyncResult
戻り値
非同期の読み取りを参照する IAsyncResult。


非同期の BeginReceive 操作は、EndReceive メソッドを呼び出して終了させる必要があります。通常、このメソッドは callback デリゲートによって呼び出されます。
このメソッドは、操作が完了するまでブロックしません。操作が完了するまでブロックするには、Receive メソッド オーバーロードのいずれかを使用します。
保留中の BeginReceive をキャンセルするには、Close メソッドを呼び出します。
非同期プログラミング モデルの使用法の詳細については、「同期メソッドの非同期呼び出し」を参照してください。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode プロパティを使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認してください。これは MSDN ライブラリから入手できます。 |
![]() |
---|
このメンバは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。詳細については、「ネットワークのトレース」を参照してください。 |

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Socket.BeginReceive メソッド (Byte[], Int32, Int32, SocketFlags, AsyncCallback, Object)
アセンブリ: System (system.dll 内)

Public Function BeginReceive ( _ buffer As Byte(), _ offset As Integer, _ size As Integer, _ socketFlags As SocketFlags, _ callback As AsyncCallback, _ state As Object _ ) As IAsyncResult
Dim instance As Socket Dim buffer As Byte() Dim offset As Integer Dim size As Integer Dim socketFlags As SocketFlags Dim callback As AsyncCallback Dim state As Object Dim returnValue As IAsyncResult returnValue = instance.BeginReceive(buffer, offset, size, socketFlags, callback, state)
public IAsyncResult BeginReceive ( byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, Object state )
public: IAsyncResult^ BeginReceive ( array<unsigned char>^ buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback^ callback, Object^ state )
public IAsyncResult BeginReceive ( byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, Object state )
public function BeginReceive ( buffer : byte[], offset : int, size : int, socketFlags : SocketFlags, callback : AsyncCallback, state : Object ) : IAsyncResult
戻り値
非同期の読み取りを参照する IAsyncResult。


非同期の BeginReceive 操作は、EndReceive メソッドを呼び出して終了させる必要があります。通常、このメソッドは callback デリゲートによって呼び出されます。
このメソッドは、操作が完了するまでブロックしません。操作が完了するまでブロックするには、Receive メソッド オーバーロードのいずれかを使用します。
保留中の BeginReceive をキャンセルするには、Close メソッドを呼び出します。
非同期プログラミング モデルの使用法の詳細については、「同期メソッドの非同期呼び出し」を参照してください。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode プロパティを使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認してください。これは MSDN ライブラリから入手できます。 |
![]() |
---|
このメンバは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。詳細については、「ネットワークのトレース」を参照してください。 |

接続されている Socket から、データの非同期の受信を開始するコード例を次に示します。
Public Class StateObject Public workSocket As Socket = Nothing Public const BUFFER_SIZE As Integer = 1024 Public buffer(BUFFER_SIZE) As byte Public sb As New StringBuilder() End Class 'StateObject
public class StateObject{ public Socket workSocket = null; public const int BUFFER_SIZE = 1024; public byte[] buffer = new byte[BUFFER_SIZE]; public StringBuilder sb = new StringBuilder(); }
public ref class StateObject { public: literal int BUFFER_SIZE = 1024; Socket^ workSocket; array<Byte>^ buffer; StringBuilder^ sb; StateObject() : workSocket( nullptr ) { buffer = gcnew array<Byte>(BUFFER_SIZE); sb = gcnew StringBuilder; } };
Public Shared Sub Listen_Callback(ar As IAsyncResult) allDone.Set() Dim s As Socket = CType(ar.AsyncState, Socket) Dim s2 As Socket = s.EndAccept(ar) Dim so2 As New StateObject() so2.workSocket = s2 s2.BeginReceive(so2.buffer, 0, StateObject.BUFFER_SIZE, 0, New AsyncCallback(AddressOf Async_Send_Receive.Read_Callback), so2) End Sub 'Listen_Callback
public static void Listen_Callback(IAsyncResult ar){ allDone.Set(); Socket s = (Socket) ar.AsyncState; Socket s2 = s.EndAccept(ar); StateObject so2 = new StateObject(); so2.workSocket = s2; s2.BeginReceive(so2.buffer, 0, StateObject.BUFFER_SIZE,0, new AsyncCallback(Async_Send_Receive.Read_Callback), so2); }
static void Listen_Callback( IAsyncResult^ ar ) { allDone->Set(); Socket^ s = safe_cast<Socket^>(ar->AsyncState); Socket^ s2 = s->EndAccept( ar ); StateObject^ so2 = gcnew StateObject; so2->workSocket = s2; s2->BeginReceive( so2->buffer, 0, StateObject::BUFFER_SIZE, SocketFlags::None , gcnew AsyncCallback( &Async_Send_Receive::Read_Callback ), so2 ); }
allDone.Set(); Socket s = (Socket)ar.get_AsyncState(); Socket s2 = s.EndAccept(ar); StateObject so2 = new StateObject(); so2.workSocket = s2; s2.BeginReceive(so2.buffer, 0, StateObject.BUFFER_SIZE, (SocketFlags)0, new AsyncCallback(Async_Send_Receive.Read_Callback) , so2);
Public Shared Sub Read_Callback(ar As IAsyncResult) Dim so As StateObject = CType(ar.AsyncState, StateObject) Dim s As Socket = so.workSocket Dim read As Integer = s.EndReceive(ar) If read > 0 Then so.sb.Append(Encoding.ASCII.GetString(so.buffer, 0, read)) s.BeginReceive(so.buffer, 0, StateObject.BUFFER_SIZE, 0, New AsyncCallback(AddressOf Async_Send_Receive.Read_Callback), so) Else If so.sb.Length > 1 Then 'All the data has been read, so displays it to the console Dim strContent As String strContent = so.sb.ToString() Console.WriteLine([String].Format("Read {0} byte from socket" + "data = {1} ", strContent.Length, strContent)) End If s.Close() End If End Sub 'Read_Callback
public static void Read_Callback(IAsyncResult ar){ StateObject so = (StateObject) ar.AsyncState; Socket s = so.workSocket; int read = s.EndReceive(ar); if (read > 0) { so.sb.Append(Encoding.ASCII.GetString(so.buffer, 0, read)); s.BeginReceive(so.buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(Async_Send_Receive.Read_Callback), so); } else{ if (so.sb.Length > 1) { //All of the data has been read, so displays it to the console string strContent; strContent = so.sb.ToString(); Console.WriteLine(String.Format("Read {0} byte from socket" + "data = {1} ", strContent.Length, strContent)); } s.Close(); } }
static void Read_Callback( IAsyncResult^ ar ) { StateObject^ so = safe_cast<StateObject^>(ar->AsyncState); Socket^ s = so->workSocket; int read = s->EndReceive( ar ); if ( read > 0 ) { so->sb->Append( Encoding::ASCII->GetString( so->buffer, 0, read ) ); s->BeginReceive( so->buffer, 0, StateObject::BUFFER_SIZE, SocketFlags::None , gcnew AsyncCallback( &Async_Send_Receive::Read_Callback ), so ); } else { if ( so->sb->Length > 1 ) { //All of the data has been read, so displays it to the console String^ strContent = so->sb->ToString(); Console::WriteLine( String::Format( "Read {0} byte from socket" + " data = {1} ", strContent->Length, strContent ) ); } s->Close(); } }
StateObject so = (StateObject)ar.get_AsyncState(); Socket s = so.workSocket; int read = s.EndReceive(ar); if (read > 0) { so.sb.Append(Encoding.get_ASCII().GetString(so.buffer, 0, read)); s.BeginReceive(so.buffer, 0, StateObject.BUFFER_SIZE, (SocketFlags)0, new AsyncCallback(Async_Send_Receive. Read_Callback), so); } else { if (so.sb.get_Length() > 1) { //All of the data has been read, so displays it to the console String strContent; strContent = so.sb.ToString(); Console.WriteLine(String.Format("Read {0} byte from socket" + "data = {1} ", (Int32)strContent.get_Length(), strContent)); } s.Close(); }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Socket.BeginReceive メソッド (ジェネリック IList, SocketFlags, SocketError, AsyncCallback, Object)
アセンブリ: System (system.dll 内)

<CLSCompliantAttribute(False)> _ Public Function BeginReceive ( _ buffers As IList(Of ArraySegment(Of Byte)), _ socketFlags As SocketFlags, _ <OutAttribute> ByRef errorCode As SocketError, _ callback As AsyncCallback, _ state As Object _ ) As IAsyncResult
Dim instance As Socket Dim buffers As IList(Of ArraySegment(Of Byte)) Dim socketFlags As SocketFlags Dim errorCode As SocketError Dim callback As AsyncCallback Dim state As Object Dim returnValue As IAsyncResult returnValue = instance.BeginReceive(buffers, socketFlags, errorCode, callback, state)
[CLSCompliantAttribute(false)] public IAsyncResult BeginReceive ( IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, Object state )
[CLSCompliantAttribute(false)] public: IAsyncResult^ BeginReceive ( IList<ArraySegment<unsigned char>>^ buffers, SocketFlags socketFlags, [OutAttribute] SocketError% errorCode, AsyncCallback^ callback, Object^ state )
/** @attribute CLSCompliantAttribute(false) */ public IAsyncResult BeginReceive ( IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, /** @attribute OutAttribute() */ /** @ref */ SocketError errorCode, AsyncCallback callback, Object state )
戻り値
非同期の読み取りを参照する IAsyncResult。


非同期の BeginReceive 操作は、EndReceive メソッドを呼び出して終了させる必要があります。通常、このメソッドは callback デリゲートによって呼び出されます。
このメソッドは、操作が完了するまでブロックしません。操作が完了するまでブロックするには、Receive メソッド オーバーロードのいずれかを使用します。
保留中の BeginReceive をキャンセルするには、Close メソッドを呼び出します。
非同期プログラミング モデルの使用法の詳細については、「同期メソッドの非同期呼び出し」を参照してください。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode プロパティを使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認してください。これは MSDN ライブラリから入手できます。 |
![]() |
---|
このメンバは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。詳細については、「ネットワークのトレース」を参照してください。 |

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Socket.BeginReceive メソッド (Byte[], Int32, Int32, SocketFlags, SocketError, AsyncCallback, Object)
アセンブリ: System (system.dll 内)

Public Function BeginReceive ( _ buffer As Byte(), _ offset As Integer, _ size As Integer, _ socketFlags As SocketFlags, _ <OutAttribute> ByRef errorCode As SocketError, _ callback As AsyncCallback, _ state As Object _ ) As IAsyncResult
Dim instance As Socket Dim buffer As Byte() Dim offset As Integer Dim size As Integer Dim socketFlags As SocketFlags Dim errorCode As SocketError Dim callback As AsyncCallback Dim state As Object Dim returnValue As IAsyncResult returnValue = instance.BeginReceive(buffer, offset, size, socketFlags, errorCode, callback, state)
public IAsyncResult BeginReceive ( byte[] buffer, int offset, int size, SocketFlags socketFlags, out SocketError errorCode, AsyncCallback callback, Object state )
public: IAsyncResult^ BeginReceive ( array<unsigned char>^ buffer, int offset, int size, SocketFlags socketFlags, [OutAttribute] SocketError% errorCode, AsyncCallback^ callback, Object^ state )
public IAsyncResult BeginReceive ( byte[] buffer, int offset, int size, SocketFlags socketFlags, /** @attribute OutAttribute() */ /** @ref */ SocketError errorCode, AsyncCallback callback, Object state )
戻り値
非同期の読み取りを参照する IAsyncResult。


非同期の BeginReceive 操作は、EndReceive メソッドを呼び出して終了させる必要があります。通常、このメソッドは callback デリゲートによって呼び出されます。
このメソッドは、操作が完了するまでブロックしません。操作が完了するまでブロックするには、Receive メソッド オーバーロードのいずれかを使用します。
保留中の BeginReceive をキャンセルするには、Close メソッドを呼び出します。
非同期プログラミング モデルの使用法の詳細については、「同期メソッドの非同期呼び出し」を参照してください。
![]() |
---|
SocketException が発生した場合は、SocketException.ErrorCode プロパティを使用して具体的なエラー コードを取得してください。このコードを取得したら、Windows Socket Version 2 API エラー コードのドキュメントでエラーの詳細情報を確認してください。これは MSDN ライブラリから入手できます。 |
![]() |
---|
このメンバは、アプリケーションでネットワーク トレースが有効にされている場合にトレース情報を出力します。詳細については、「ネットワークのトレース」を参照してください。 |

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Socket.BeginReceive メソッド

名前 | 説明 |
---|---|
Socket.BeginReceive (ジェネリック IList, SocketFlags, AsyncCallback, Object) | 接続されている Socket からの非同期のデータ受信を開始します。 |
Socket.BeginReceive (ジェネリック IList, SocketFlags, SocketError, AsyncCallback, Object) | 接続されている Socket からの非同期のデータ受信を開始します。 |
Socket.BeginReceive (Byte[], Int32, Int32, SocketFlags, AsyncCallback, Object) | 接続されている Socket からの非同期のデータ受信を開始します。 .NET Compact Framework によってサポートされています。 |
Socket.BeginReceive (Byte[], Int32, Int32, SocketFlags, SocketError, AsyncCallback, Object) | 接続されている Socket からの非同期のデータ受信を開始します。 |

Weblioに収録されているすべての辞書からSocket.BeginReceiveを検索する場合は、下記のリンクをクリックしてください。

- Socket.BeginReceiveのページへのリンク