SIPSorcery.SIP.SIPUDPChannel.Listen C# (CSharp) Method

Listen() private method

private Listen ( ) : void
return void
        private void Listen()
        {
            try
            {
                byte[] buffer = null;

                logger.Debug("SIPUDPChannel socket on " + m_localSIPEndPoint.ToString() + " listening started.");

                while(!Closed)
                {
                    IPEndPoint inEndPoint = new IPEndPoint(IPAddress.Any, 0);

                    try
                    {
                        buffer = m_sipConn.Receive(ref inEndPoint);
                    }
                    catch (SocketException)
                    {
                        // ToDo. Pretty sure these exceptions get thrown when an ICMP message comes back indicating there is no listening
                        // socket on the other end. It would be nice to be able to relate that back to the socket that the data was sent to
                        // so that we know to stop sending.
                        //logger.Warn("SocketException SIPUDPChannel Receive (" + sockExcp.ErrorCode + "). " + sockExcp.Message);

                        //inEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Any, 0));
                        continue;
                    }
                    catch(Exception listenExcp)
                    {
                        // There is no point logging this as without processing the ICMP message it's not possible to know which socket the rejection came from.
                        logger.Error("Exception listening on SIPUDPChannel. " + listenExcp.Message);

                        inEndPoint = new IPEndPoint(IPAddress.Any, 0);
                        continue;
                    }

                    if(buffer == null || buffer.Length == 0)
                    {
                        // No need to care about zero byte packets.
                        //string remoteEndPoint = (inEndPoint != null) ? inEndPoint.ToString() : "could not determine";
                        //logger.Error("Zero bytes received on SIPUDPChannel " + m_localSIPEndPoint.ToString() + ".");
                    }
                    else
                    {
                        if(SIPMessageReceived != null)
                        {
                            SIPMessageReceived(this, new SIPEndPoint(SIPProtocolsEnum.udp, inEndPoint), buffer);
                        }
                    }
                }

                logger.Debug("SIPUDPChannel socket on " + m_localSIPEndPoint + " listening halted.");
            }
            catch(Exception excp)
            {
                logger.Error("Exception SIPUDPChannel Listen. " + excp.Message);
                //throw excp;
            }
        }