Example #1
0
        /// <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);
        }
Example #2
0
 /// <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);
 }
Example #3
0
 /// <summary>
 /// Recieve data, and process it in the main thread.
 /// </summary>
 public override void BeginRecieve(AsyncByteCallback requestCallback)
 {
     base.BeginRecieve(recievedBytes => QueueForProcessing(recievedBytes, requestCallback));
 }
Example #4
0
 /// <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));
 }
Example #5
0
 public AsyncThreadCallback(byte[] recievedBytes, AsyncByteCallback requestCallback)
 {
     RequestCallback = requestCallback;
     RecievedBytes   = recievedBytes;
 }