/// <summary> /// Handles the received UDP message event. /// </summary> /// <param name="ar">The <see cref="IAsyncResult"/> object that contains necessary meta data.</param> private void ReceiveUdpMessage(IAsyncResult ar) { UdpClient client = ((UdpState)ar.AsyncState).Client; IPEndPoint receivedIpEndPoint = new IPEndPoint( IPAddress.Any , 0); Byte[] receiveBytes; try { receiveBytes = client.EndReceive( ar , ref receivedIpEndPoint); } catch (ObjectDisposedException) { // The socket seems to be already closed. return; } if (receiveBytes != null) { try { LogMessage newLogMsg = new LogMessageSyslog( Encoding.ASCII.GetString(receiveBytes) , ++mLogNumber); if (mLogHandler != null) { mLogHandler.HandleMessage(newLogMsg); } } catch (Exception ex) { Logger.Warn(ex.Message); } } client.BeginReceive(ReceiveUdpMessage, ar.AsyncState); }