BeginRead Method
-
In the documentation on this method it says i can extract the read data within the callback method? i dont understand how to do this... eg NetworkStream str = (NetworkStream) result.AsyncState; byte[] myReadBuffer = new byte[2048]; int numberOfBytesRead = 0; numberOfBytesRead = str.EndRead(result); it says "To obtain the received data, call the AsyncState method of the IAsyncResult, and extract the buffer contained in the resulting state object" so in my case the IAsyncResult = result and I case the stream state from it but how do i get the data? as theres no method to call?? confused :) mike
-
In the documentation on this method it says i can extract the read data within the callback method? i dont understand how to do this... eg NetworkStream str = (NetworkStream) result.AsyncState; byte[] myReadBuffer = new byte[2048]; int numberOfBytesRead = 0; numberOfBytesRead = str.EndRead(result); it says "To obtain the received data, call the AsyncState method of the IAsyncResult, and extract the buffer contained in the resulting state object" so in my case the IAsyncResult = result and I case the stream state from it but how do i get the data? as theres no method to call?? confused :) mike
Create a object which looks something like this class ObjectState { public byte[] myReadBuffer = new byte[2048]; public NetworkStream str = set the network stream object u had created } now when you call beginread call it this way ObjectState state = new ObjectState(); networkstream.BeginRead(state.myReadBuffer, 0, 2048, AsyncCallback method pointer, state) //Pass state object to last parameter of BeginRead. when u endread ObjectState state; state = (objectState) result.AsyncState; int numberOfBytesRead = 0; numberOfBytesRead = str.EndRead(result); now use state.myReadBuffer; //This should contain the data u r looking for