/// <summary> /// Creates a SIP channel to listen for and send SIP messages over UDP. /// </summary> /// <param name="endPoint">The IP end point to listen on and send from.</param> /// <param name="useDualMode">If true then IPv6 sockets will be created as dual mode IPv4/IPv6 on supporting systems.</param> public SIPUDPChannel(IPEndPoint endPoint, bool useDualMode = false) : base() { if (endPoint == null) { throw new ArgumentNullException("endPoint", "The end point must be specified when creating a SIPUDPChannel."); } ListeningIPAddress = endPoint.Address; Port = endPoint.Port; SIPProtocol = SIPProtocolsEnum.udp; IsReliable = false; m_cts = new CancellationTokenSource(); m_udpSocket = NetServices.CreateBoundUdpSocket(endPoint.Port, endPoint.Address, false, useDualMode); if (endPoint.Port == 0) { Port = (m_udpSocket.LocalEndPoint as IPEndPoint).Port; } m_recvBuffer = new byte[SIPConstants.SIP_MAXIMUM_RECEIVE_LENGTH]; logger.LogInformation($"SIP UDP Channel created for {ListeningEndPoint}."); Receive(); Task.Factory.StartNew(ExpireFailedSends, TaskCreationOptions.LongRunning); }
public void CheckFailsOnDuplicateForIP6AnyThenIPv4AnyUnitTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); if (Socket.OSSupportsIPv6 && NetServices.SupportsDualModeIPv4PacketInfo) { Socket rtpSocket = null; Socket controlSocket = null; NetServices.CreateRtpSocket(true, IPAddress.IPv6Any, out rtpSocket, out controlSocket); Assert.NotNull(rtpSocket); Assert.NotNull(controlSocket); Assert.Throws <ApplicationException>(() => NetServices.CreateBoundUdpSocket((rtpSocket.LocalEndPoint as IPEndPoint).Port, IPAddress.Any)); rtpSocket.Close(); controlSocket.Close(); } else { logger.LogDebug("Test skipped as IPv6 dual mode sockets are not in use on this OS."); } }
public STUNServer(IPEndPoint primaryEndPoint, STUNSendMessageDelegate primarySend, IPEndPoint secondaryEndPoint, STUNSendMessageDelegate secondarySend) { m_primaryEndPoint = primaryEndPoint; m_primarySend = primarySend; m_secondaryEndPoint = secondaryEndPoint; m_secondarySend = secondarySend; //m_primaryDiffPortSocket = NetServices.CreateRandomUDPListener(m_primaryEndPoint.Address, out m_primaryDiffPortEndPoint); //m_secondaryDiffPortSocket = NetServices.CreateRandomUDPListener(m_secondaryEndPoint.Address, out m_secondaryDiffPortEndPoint); m_primaryDiffPortSocket = new UdpClient(); m_primaryDiffPortSocket.Client = NetServices.CreateBoundUdpSocket(0, m_primaryEndPoint.Address); m_primaryDiffPortEndPoint = m_primaryDiffPortSocket.Client.LocalEndPoint as IPEndPoint; m_secondaryDiffPortSocket = new UdpClient(); m_secondaryDiffPortSocket.Client = NetServices.CreateBoundUdpSocket(0, m_primaryEndPoint.Address); m_secondaryDiffPortEndPoint = m_secondaryDiffPortSocket.Client.LocalEndPoint as IPEndPoint; logger.LogDebug("STUN Server additional sockets, primary=" + IPSocket.GetSocketString(m_primaryDiffPortEndPoint) + ", secondary=" + IPSocket.GetSocketString(m_secondaryDiffPortEndPoint) + "."); }