static void Main(string[] args) { try { IPAddress IPAddressOne = IPAddress.Parse(ConfigurationManager.AppSettings[IPADDRESS_ONE_KEY]); ; int PortOne = Convert.ToInt32(ConfigurationManager.AppSettings[PORT_ONE_KEY]); IPAddress IPAddressTwo = IPAddress.Parse(ConfigurationManager.AppSettings[IPADDRESS_TWO_KEY]); int PortTwo = Convert.ToInt32(ConfigurationManager.AppSettings[PORT_TWO_KEY]); IPEndPoint primaryEndPoint = new IPEndPoint(IPAddressOne, PortOne); IPEndPoint secondaryEndPoint = new IPEndPoint(IPAddressTwo, PortTwo); // Create the two listeners to receive STUN requests. STUNListener primaryListener = new STUNListener(primaryEndPoint); STUNListener secondaryListener = new STUNListener(secondaryEndPoint); // Wire up the STUN server to process the requests. STUNServer stunServer = new STUNServer(primaryEndPoint, primaryListener.Send, secondaryEndPoint, secondaryListener.Send); primaryListener.MessageReceived += new STUNMessageReceived(stunServer.STUNPrimaryReceived); secondaryListener.MessageReceived += new STUNMessageReceived(stunServer.STUNSecondaryReceived); ManualResetEvent dontStopEvent = new ManualResetEvent(false); dontStopEvent.WaitOne(); } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp.Message); Console.ReadLine(); } }
static void Main(string[] args) { try { IPAddress IPAddressOne = IPAddress.Parse(ConfigurationManager.AppSettings[IPADDRESS_ONE_KEY]);; int PortOne = Convert.ToInt32(ConfigurationManager.AppSettings[PORT_ONE_KEY]); IPAddress IPAddressTwo = IPAddress.Parse(ConfigurationManager.AppSettings[IPADDRESS_TWO_KEY]); int PortTwo = Convert.ToInt32(ConfigurationManager.AppSettings[PORT_TWO_KEY]); IPEndPoint primaryEndPoint = new IPEndPoint(IPAddressOne, PortOne); IPEndPoint secondaryEndPoint = new IPEndPoint(IPAddressTwo, PortTwo); // Create the two listeners to receive STUN requests. STUNListener primaryListener = new STUNListener(primaryEndPoint); STUNListener secondaryListener = new STUNListener(secondaryEndPoint); // Wire up the STUN server to process the requests. STUNServer stunServer = new STUNServer(primaryEndPoint, primaryListener.Send, secondaryEndPoint, secondaryListener.Send); primaryListener.MessageReceived += new STUNMessageReceived(stunServer.STUNPrimaryReceived); secondaryListener.MessageReceived += new STUNMessageReceived(stunServer.STUNSecondaryReceived); ManualResetEvent dontStopEvent = new ManualResetEvent(false); dontStopEvent.WaitOne(); } catch (Exception excp) { Console.WriteLine("Exception Main. " + excp.Message); Console.ReadLine(); } }
private void StartSTUNServer(IPEndPoint primaryEndPoint, IPEndPoint secondaryEndPoint, SIPTransport sipTransport) { STUNListener secondarySTUNListener = new STUNListener(secondaryEndPoint); // This end point is only for secondary STUN messages. STUNSendMessageDelegate primarySend = (dst, buffer) => { m_sipTransport.SendRaw(m_sipTransport.GetDefaultSIPEndPoint(SIPProtocolsEnum.udp), new SIPEndPoint(dst), buffer); }; m_stunServer = new STUNServer(primaryEndPoint, primarySend, secondaryEndPoint, secondarySTUNListener.Send); sipTransport.STUNRequestReceived += m_stunServer.STUNPrimaryReceived; sipTransport.STUNRequestReceived += LogPrimarySTUNRequestReceived; secondarySTUNListener.MessageReceived += m_stunServer.STUNSecondaryReceived; secondarySTUNListener.MessageReceived += LogSecondarySTUNRequestReceived; logger.Debug("STUN server successfully initialised."); }