/// <summary> /// Extracts the bytes from the UDP response and invokes the callback. /// </summary> /// <param name="requestCallback"></param> /// <param name="result"></param> public void ProcessRecieve(AsyncByteCallback requestCallback, IAsyncResult result) { var sender = new IPEndPoint(IPAddress.Any, 0); var listner = (UdpClient)result.AsyncState; var recievedBytes = listner.EndReceive(result, ref sender); requestCallback.Invoke(recievedBytes); }
/// <summary> /// Recieve data, and direct response to given callback. /// </summary> /// <param name="requestCallback">Method to invoked when message recieved.</param> public virtual void BeginRecieve(AsyncByteCallback requestCallback) { _client.BeginReceive(result => ProcessRecieve(requestCallback, result), _client); }
/// <summary> /// Recieve data, and process it in the main thread. /// </summary> public override void BeginRecieve(AsyncByteCallback requestCallback) { base.BeginRecieve(recievedBytes => QueueForProcessing(recievedBytes, requestCallback)); }
/// <summary> /// Add the async message to the queue to be processed int the main thread. /// </summary> /// <param name="requestCallback"></param> /// <param name="result"></param> private void QueueForProcessing(byte[] recievedBytes, AsyncByteCallback requestCallback) { _threadProcessor.Enqueue(new AsyncThreadCallback(recievedBytes, requestCallback)); }
public AsyncThreadCallback(byte[] recievedBytes, AsyncByteCallback requestCallback) { RequestCallback = requestCallback; RecievedBytes = recievedBytes; }