Ejemplo n.º 1
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Dns_Client()
        {
            m_pTransactions = new Dictionary<int,DNS_ClientTransaction>();

            m_pIPv4Socket = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
            m_pIPv4Socket.Bind(new IPEndPoint(IPAddress.Any,0));

            if(Socket.OSSupportsIPv6){
                m_pIPv6Socket = new Socket(AddressFamily.InterNetworkV6,SocketType.Dgram,ProtocolType.Udp);
                m_pIPv6Socket.Bind(new IPEndPoint(IPAddress.IPv6Any,0));
            }

            m_pReceivers = new List<UDP_DataReceiver>();

            // Create UDP data receivers.
            for(int i=0;i<5;i++){
                UDP_DataReceiver ipv4Receiver = new UDP_DataReceiver(m_pIPv4Socket);
                ipv4Receiver.PacketReceived += delegate(object s1,UDP_e_PacketReceived e1){
                    ProcessUdpPacket(e1);
                };
                m_pReceivers.Add(ipv4Receiver);
                ipv4Receiver.Start();

                if(m_pIPv6Socket != null){
                    UDP_DataReceiver ipv6Receiver = new UDP_DataReceiver(m_pIPv6Socket);
                    ipv6Receiver.PacketReceived += delegate(object s1,UDP_e_PacketReceived e1){
                        ProcessUdpPacket(e1);
                    };
                    m_pReceivers.Add(ipv6Receiver);
                    ipv6Receiver.Start();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts UDP server.
        /// </summary>
        public void Start()
        {
            if(m_IsRunning){
                return;
            }
            m_IsRunning = true;

            m_StartTime = DateTime.Now;
            m_pDataReceivers = new List<UDP_DataReceiver>();

            // Run only if we have some listening point.
            if(m_pBindings != null){
                // We must replace IPAddress.Any to all available IPs, otherwise it's impossible to send 
                // reply back to UDP packet sender on same local EP where packet received. This is very 
                // important when clients are behind NAT.
                List<IPEndPoint> listeningEPs = new List<IPEndPoint>();
                foreach(IPEndPoint ep in m_pBindings){                    
                    if(ep.Address.Equals(IPAddress.Any)){
                        // Add localhost.
                        IPEndPoint epLocalhost = new IPEndPoint(IPAddress.Loopback,ep.Port);
                        if(!listeningEPs.Contains(epLocalhost)){
                            listeningEPs.Add(epLocalhost);
                        }
                        // Add all host IPs.
                        foreach(IPAddress ip in System.Net.Dns.GetHostAddresses("")){
                            IPEndPoint epNew = new IPEndPoint(ip,ep.Port);
                            if(!listeningEPs.Contains(epNew)){
                                listeningEPs.Add(epNew);
                            }
                        }
                    }
                    else{
                        if(!listeningEPs.Contains(ep)){
                            listeningEPs.Add(ep);
                        }
                    }
                }

                // Create sockets.
                m_pSockets = new List<Socket>();
                foreach(IPEndPoint ep in listeningEPs){                    
                    try{
                        Socket socket = Net_Utils.CreateSocket(ep,ProtocolType.Udp);
                        m_pSockets.Add(socket);

                        // Create UDP data receivers.
                        for(int i=0;i<m_ReceiversPerSocket;i++){
                            UDP_DataReceiver receiver = new UDP_DataReceiver(socket);
                            receiver.PacketReceived += delegate(object s,UDP_e_PacketReceived e){
                                try{
                                    ProcessUdpPacket(e);
                                }
                                catch(Exception x){
                                    OnError(x);
                                }
                            };
                            receiver.Error += delegate(object s,ExceptionEventArgs e){
                                OnError(e.Exception);
                            };
                            m_pDataReceivers.Add(receiver);
                            receiver.Start();
                        }
                    }
                    catch(Exception x){
                        OnError(x);
                    }
                }
           
                // Create round-robin send sockets. NOTE: We must skip localhost, it can't be used 
                // for sending out of server.
                m_pSendSocketsIPv4 = new CircleCollection<Socket>();
                m_pSendSocketsIPv6 = new CircleCollection<Socket>();
                foreach(Socket socket in m_pSockets){
                    if(((IPEndPoint)socket.LocalEndPoint).AddressFamily == AddressFamily.InterNetwork){
                        if(!((IPEndPoint)socket.LocalEndPoint).Address.Equals(IPAddress.Loopback)){                            
                            m_pSendSocketsIPv4.Add(socket);
                        }
                    }
                    else if(((IPEndPoint)socket.LocalEndPoint).AddressFamily == AddressFamily.InterNetworkV6){
                        m_pSendSocketsIPv6.Add(socket);
                    }                    
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts RTP session.
        /// </summary>
        /// <exception cref="ObjectDisposedException">Is raised when this class is Disposed and this method is accessed.</exception>
        public void Start()
        {
            if(m_IsDisposed){
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if(m_IsStarted){
                return;
            }
            m_IsStarted = true;

            /* RFC 3550 6.3.2 Initialization
                Upon joining the session, the participant initializes tp to 0, tc to
                0, senders to 0, pmembers to 1, members to 1, we_sent to false,
                rtcp_bw to the specified fraction of the session bandwidth, initial
                to true, and avg_rtcp_size to the probable size of the first RTCP
                packet that the application will later construct.  The calculated
                interval T is then computed, and the first packet is scheduled for
                time tn = T.  This means that a transmission timer is set which
                expires at time T.  Note that an application MAY use any desired
                approach for implementing this timer.
    
                The participant adds its own SSRC to the member table.
            */

            m_PMembersCount = 1;
            m_RtcpAvgPacketSize = 100;

            // Add ourself to members list.
            m_pRtcpSource = CreateLocalSource();
            m_pMembers.Add(m_pRtcpSource.SSRC,m_pRtcpSource);

            // Create RTP data receiver.
            UDP_DataReceiver rtpDataReceiver = new UDP_DataReceiver(m_pRtpSocket);
            rtpDataReceiver.PacketReceived += delegate(object s1,UDP_e_PacketReceived e1){
                ProcessRtp(e1.Buffer,e1.Count,e1.RemoteEP);
            };
            // rtpDataReceiver.Error // We don't care about receiving errors here.
            m_pUdpDataReceivers.Add(rtpDataReceiver);
            rtpDataReceiver.Start();
            // Create RTCP data receiver.
            UDP_DataReceiver rtcpDataReceiver = new UDP_DataReceiver(m_pRtcpSocket);
            rtcpDataReceiver.PacketReceived += delegate(object s1,UDP_e_PacketReceived e1){
                ProcessRtcp(e1.Buffer,e1.Count,e1.RemoteEP);
            };
            // rtcpDataReceiver.Error // We don't care about receiving errors here.
            m_pUdpDataReceivers.Add(rtcpDataReceiver);
            rtcpDataReceiver.Start();           
                   
            // Start RTCP reporting.
            Schedule(ComputeRtcpTransmissionInterval(m_pMembers.Count,m_pSenders.Count,m_Bandwidth * 0.25,false,m_RtcpAvgPacketSize,true));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts UDP server.
        /// </summary>
        public void Start()
        {
            if (m_IsRunning)
            {
                return;
            }
            m_IsRunning = true;

            m_StartTime      = DateTime.Now;
            m_pDataReceivers = new List <UDP_DataReceiver>();

            // Run only if we have some listening point.
            if (m_pBindings != null)
            {
                // We must replace IPAddress.Any to all available IPs, otherwise it's impossible to send
                // reply back to UDP packet sender on same local EP where packet received. This is very
                // important when clients are behind NAT.
                List <IPEndPoint> listeningEPs = new List <IPEndPoint>();
                foreach (IPEndPoint ep in m_pBindings)
                {
                    if (ep.Address.Equals(IPAddress.Any))
                    {
                        // Add localhost.
                        IPEndPoint epLocalhost = new IPEndPoint(IPAddress.Loopback, ep.Port);
                        if (!listeningEPs.Contains(epLocalhost))
                        {
                            listeningEPs.Add(epLocalhost);
                        }
                        // Add all host IPs.
                        foreach (IPAddress ip in Helpers.GetHostAddresses(""))
                        {
                            IPEndPoint epNew = new IPEndPoint(ip, ep.Port);
                            if (!listeningEPs.Contains(epNew))
                            {
                                listeningEPs.Add(epNew);
                            }
                        }
                    }
                    else
                    {
                        if (!listeningEPs.Contains(ep))
                        {
                            listeningEPs.Add(ep);
                        }
                    }
                }

                // Create sockets.
                m_pSockets = new List <Socket>();
                foreach (IPEndPoint ep in listeningEPs)
                {
                    try{
                        Socket socket = Net_Utils.CreateSocket(ep, ProtocolType.Udp);
                        m_pSockets.Add(socket);

                        // Create UDP data receivers.
                        for (int i = 0; i < m_ReceiversPerSocket; i++)
                        {
                            UDP_DataReceiver receiver = new UDP_DataReceiver(socket);
                            receiver.PacketReceived += delegate(object s, UDP_e_PacketReceived e){
                                try{
                                    ProcessUdpPacket(e);
                                }
                                catch (Exception x) {
                                    OnError(x);
                                }
                            };
                            receiver.Error += delegate(object s, ExceptionEventArgs e){
                                OnError(e.Exception);
                            };
                            m_pDataReceivers.Add(receiver);
                            receiver.Start();
                        }
                    }
                    catch (Exception x) {
                        OnError(x);
                    }
                }

                // Create round-robin send sockets. NOTE: We must skip localhost, it can't be used
                // for sending out of server.
                m_pSendSocketsIPv4 = new CircleCollection <Socket>();
                m_pSendSocketsIPv6 = new CircleCollection <Socket>();
                foreach (Socket socket in m_pSockets)
                {
                    if (((IPEndPoint)socket.LocalEndPoint).AddressFamily == AddressFamily.InterNetwork)
                    {
                        if (!((IPEndPoint)socket.LocalEndPoint).Address.Equals(IPAddress.Loopback))
                        {
                            m_pSendSocketsIPv4.Add(socket);
                        }
                    }
                    else if (((IPEndPoint)socket.LocalEndPoint).AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        m_pSendSocketsIPv6.Add(socket);
                    }
                }
            }
        }