SIPSorcery.Net.STUNListener.Listen C# (CSharp) Method

Listen() private method

private Listen ( ) : void
return void
        private void Listen()
        {
            try
            {
                UdpClient stunConn = m_stunConn;

                IPEndPoint inEndPoint = new IPEndPoint(IPAddress.Any, 0);
                byte[] buffer = null;

                Thread.CurrentThread.Name = STUN_LISTENER_THREAD_NAME + inEndPoint.Port.ToString();

                while(!m_closed)
                {
                    try
                    {
                        buffer = stunConn.Receive(ref inEndPoint);
                    }
                    catch(Exception bufExcp)
                    {
                        logger.Error("Exception listening in STUNListener. " + bufExcp.Message + ".");
                        inEndPoint = new IPEndPoint(IPAddress.Any, 0);
                        continue;
                    }

                    if(buffer == null || buffer.Length == 0)
                    {
                        logger.Error("Unable to read from STUNListener local end point " + m_localEndPoint.Address.ToString() + ":" + m_localEndPoint.Port);
                    }
                    else
                    {
                        if(MessageReceived != null)
                        {
                            try
                            {
                                MessageReceived( m_localEndPoint, inEndPoint, buffer, buffer.Length);
                            }
                            catch (Exception excp)
                            {
                                logger.Error("Exception processing STUNListener MessageReceived. " + excp.Message);
                            }
                        }
                    }
                }
            }
            catch(Exception excp)
            {
                logger.Error("Exception STUNListener Listen. " + excp.Message);
                throw excp;
            }
        }