Ejemplo n.º 1
0
        private void sockUDP_DataArrival(object sender, SockEventArgs e)
        {
            if (e.Data.Length < 29)
            {
                return;
            }
            UDPFramePacket packet = new UDPFramePacket(e.Data);                                     //获得一侦数据的一个包

            if (packet.type == (byte)TransmitType.Video || packet.type == (byte)TransmitType.Audio) //收到音频视频数据包
            {
                if (packet.type == (byte)TransmitType.Video)                                        //触发视频数据到达事件
                {
                    OnRecVideoData(this, packet.Block);
                }
                else if (packet.type == (byte)TransmitType.Audio)//触发音频数据到达事件
                {
                    OnRecAudioData(this, packet.Block);
                }

                return;

                if (packet.PacketCount > 0 && packet.PacketCount < 33)//最大32个数据包
                {
                    lock (ReceiverFrames)
                    {
                        if (ReceiverFrames.ContainsKey(packet.Timestamp))//如果侦已经存在
                        {
                            frame f = ReceiverFrames[packet.Timestamp];
                            f.Add(packet);//将包添加到侦
                        }
                        else
                        {
                            frame f = new frame();                   //创建侦
                            f.Add(packet);                           //将包添加到侦
                            f.dateTime    = DateTime.Now;
                            f.type        = packet.type;             //设置侦类型
                            f.Timestamp   = packet.Timestamp;        //设置时间戳
                            f.PacketCount = packet.PacketCount;      //设置侦的包总数
                            ReceiverFrames.Add(packet.Timestamp, f); //添加侦
                        }
                    }
                }
            }
            else if (packet.type == (byte)TransmitType.Penetrate)//收到另一客户端请求打洞
            {
                toEP = e.RemoteIPEndPoint;
                if (packet.Block.Length > mtu)//确定MTU值
                {
                    mtu = packet.Block.Length;
                }
                if (connectedType == ConnectedType.None) //如果还未连接,继续打洞
                {
                    sockUDP.Send(toEP, packet.BaseData); //告之对方收到打洞包并向对方打洞
                }
            }
            else if (packet.type == (byte)TransmitType.getRemoteEP)//收到自己的远程主机信息
            {
                if (myRemoteEP == null)
                {
                    myRemoteEP = new IPEndPoint(packet.RemoteIP, packet.Port);//设置自己的远程主机信息
                }
            }
        }
Ejemplo n.º 2
0
        private void sockUDP_DataArrival(object sender, SockEventArgs e)
        {
            if (e.Data.Length < 29) return;
            UDPFramePacket packet = new UDPFramePacket(e.Data);//获得一侦数据的一个包

            if (packet.type == (byte)TransmitType.Video || packet.type == (byte)TransmitType.Audio)//收到音频视频数据包 
            {
                if (packet.type == (byte)TransmitType.Video)//触发视频数据到达事件
                    OnRecVideoData(this, packet.Block );
                else if (packet.type == (byte)TransmitType.Audio)//触发音频数据到达事件
                    OnRecAudioData(this, packet.Block);

                return;

                if (packet.PacketCount >0 && packet.PacketCount <33)//最大32个数据包
                {
                    lock (ReceiverFrames)
                    {
                        if (ReceiverFrames.ContainsKey(packet.Timestamp))//如果侦已经存在
                        {
                            frame f = ReceiverFrames[packet.Timestamp];
                            f.Add(packet);//将包添加到侦
                        }
                        else
                        {
                            frame f = new frame();//创建侦
                            f.Add(packet);//将包添加到侦
                            f.dateTime = DateTime.Now;
                            f.type = packet.type;//设置侦类型
                            f.Timestamp = packet.Timestamp;//设置时间戳
                            f.PacketCount = packet.PacketCount;//设置侦的包总数
                            ReceiverFrames.Add(packet.Timestamp, f);//添加侦
                        }
                    }
                }
            }
            else if (packet.type == (byte)TransmitType.Penetrate)//收到另一客户端请求打洞 
            {
                toEP = e.RemoteIPEndPoint;
                if (packet.Block.Length > mtu)//确定MTU值
                    mtu = packet.Block.Length;
                if (connectedType == ConnectedType.None)//如果还未连接,继续打洞
                    sockUDP.Send(toEP, packet.BaseData);//告之对方收到打洞包并向对方打洞 
            }
            else if (packet.type == (byte)TransmitType.getRemoteEP)//收到自己的远程主机信息 
            {
                if (myRemoteEP == null)
                    myRemoteEP = new IPEndPoint(packet.RemoteIP, packet.Port);//设置自己的远程主机信息
            }
        }