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
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.