Esempio n. 1
0
        static void Main(string[] args)
        {
            LogFactory.Assign(new ConsoleLogFactory());

            byte[] datagram = new byte[277777];
            for (int i = 0; i < datagram.Length; i++)
            {
                datagram[i] = 1;
            }

            ICollection <UdpPacket> packets = UdpPacketSplitter.Split(1024, datagram, 65535);

            foreach (var packet in packets)
            {
                Console.WriteLine(packet.ToString());
            }

            foreach (var packet in packets)
            {
                byte[]    data    = packet.ToArray();
                UdpPacket convert = UdpPacket.FromArray(data);
                Console.WriteLine(convert.ToString());
            }

            Console.ReadKey();
        }
Esempio n. 2
0
        private void WorkThread()
        {
            while (IsRunning)
            {
                _waiter.WaitOne();
                _waiter.Reset();

                while (_queue.Count > 0)
                {
                    StreamPacket packet = null;
                    if (_queue.TryDequeue(out packet))
                    {
                        RtpPacket rtpPacket = RtpPacket.FromImage(
                            RtpPayloadType.JPEG,
                            packet.SequenceNumber,
                            (long)Epoch.GetDateTimeTotalMillisecondsByYesterday(packet.Timestamp),
                            packet.Frame);

                        byte[] datagram = rtpPacket.ToArray(); // max UDP packet length limited to 65,535 bytes
                        packet.Frame.Dispose();

                        // split udp packet to many packets for reduce the size to 65507 limit by underlying IPv4 protocol
                        ICollection <UdpPacket> udpPackets = UdpPacketSplitter.Split(packet.SequenceNumber, datagram, 65507 - UdpPacket.HeaderSize);
                        foreach (var udpPacket in udpPackets)
                        {
                            byte[] udpPacketDatagram = udpPacket.ToArray();
                            // async sending
                            _udpClient.BeginSend(
                                udpPacketDatagram, udpPacketDatagram.Length,
                                packet.Destination.Address,
                                packet.Destination.Port,
                                SendCompleted, _udpClient);
                        }
                    }
                }
            }
        }