What is BeginReceive(Byte(), Int32, Int32, SocketFlags, AsyncCallback, Object) and callback method in socket?

后端 未结 1 830
野趣味
野趣味 2021-01-27 10:23

I am so new in socket programming. So, recently I am assigned to a task in socket programming using vb.net to find out why this program is allocating almost 20GB of the physical

相关标签:
1条回答
  • 2021-01-27 10:27

    According to the documentation BeginReceive "begins to asynchronously receive data from a connected Socket.". So in normal language: start receiving data while continuing execution of the program.

    In the documentation from EndReceive "the callback method must accept the IAsyncResult returned by the BeginConnect method as a parameter." and "After obtaining the Socket, you can call the EndConnect method to successfully complete the connection attempt."

    And also: "The asynchronous BeginReceive operation must be completed by calling the EndReceive method. Typically, the method is invoked by the callback delegate."

    So yes, you have to call EndReceive to get the results of the BeginReceive.

    Also, as answer to your second question: "To obtain the received data, call the AsyncState method of the IAsyncResult, and extract the buffer contained in the resulting state object." So the result is buffered in the IAsyncResult object. Extract it from there and get rid of the object to let GC collect it.

    Source: BeginReceive, EndReceive, IAsyncResult.

    0 讨论(0)
提交回复
热议问题