当前位置: 首页>>代码示例>>C#>>正文


C# UDPPacketBuffer类代码示例

本文整理汇总了C#中UDPPacketBuffer的典型用法代码示例。如果您正苦于以下问题:C# UDPPacketBuffer类的具体用法?C# UDPPacketBuffer怎么用?C# UDPPacketBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UDPPacketBuffer类属于命名空间,在下文中一共展示了UDPPacketBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OutgoingPacket

 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="client">Reference to the client this packet is destined for</param>
 /// <param name="buffer">Serialized packet data. If the flags or sequence number
 /// need to be updated, they will be injected directly into this binary buffer</param>
 /// <param name="category">Throttling category for this packet</param>
 public OutgoingPacket(LLUDPClient client, UDPPacketBuffer buffer, ThrottleOutPacketType category, UnackedPacketMethod method)
 {
     Client = client;
     Buffer = buffer;
     Category = category;
     UnackedMethod = method;
 }
开发者ID:BogusCurry,项目名称:arribasim-dev,代码行数:14,代码来源:OutgoingPacket.cs

示例2: AsyncBeginReceive

        private void AsyncBeginReceive()
        {
            lock (typeof(Constants))
            {
                if (!Constants.isClosing)
                {
                    // allocate a packet buffer
                    UDPPacketBuffer buf = new UDPPacketBuffer();

                    try
                    {
                        // kick off an async read
                        udpSocket.BeginReceiveFrom(
                            buf.Data,
                            0,
                            UDPPacketBuffer.BUFFER_SIZE,
                            SocketFlags.None,
                            ref buf.RemoteEndPoint,
                            new AsyncCallback(AsyncEndReceive),
                            buf);
                    }
                    catch (SocketException se)
                    {
                        txtReceive.Text = se.Message + System.Environment.NewLine + txtReceive.Text;
                    }
                }
            }
        }
开发者ID:kensniper,项目名称:castle-butcher,代码行数:28,代码来源:Form1.cs

示例3: OutgoingPacket

 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="client">Reference to the client this packet is destined for</param>
 /// <param name="buffer">Serialized packet data. If the flags or sequence number
 /// need to be updated, they will be injected directly into this binary buffer</param>
 /// <param name="category">Throttling category for this packet</param>
 /// <param name="resendMethod">The delegate to be called if this packet is determined to be unacknowledged</param>
 /// <param name="finishedMethod">The delegate to be called when this packet is sent</param>
 public OutgoingPacket(LLUDPClient client, UDPPacketBuffer buffer,
     ThrottleOutPacketType category, UnackedPacketMethod resendMethod,
     UnackedPacketMethod finishedMethod, Packet packet)
 {
     Client = client;
     Buffer = buffer;
     Category = category;
     UnackedMethod = resendMethod;
     FinishedMethod = finishedMethod;
     Packet = packet;
 }
开发者ID:NickyPerian,项目名称:Aurora-Sim,代码行数:20,代码来源:OutgoingPacket.cs

示例4: SendPacketData

        public void SendPacketData(byte[] data, int dataLength, PacketType type, bool doZerocode)
        {
            UDPPacketBuffer buffer = new UDPPacketBuffer(remoteEndPoint, Packet.MTU);

            // Zerocode if needed
            if (doZerocode)
            {
                try { dataLength = Helpers.ZeroEncode(data, dataLength, buffer.Data); }
                catch (IndexOutOfRangeException)
                {
                    // The packet grew larger than Packet.MTU bytes while zerocoding.
                    // Remove the MSG_ZEROCODED flag and send the unencoded data
                    // instead
                    data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
                    Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
                }
            }
            else
            {
                Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
            }
            buffer.DataLength = dataLength;

            #region Queue or Send

            NetworkManager.OutgoingPacket outgoingPacket = new NetworkManager.OutgoingPacket(this, buffer);

            // Send ACK and logout packets directly, everything else goes through the queue
            if (Client.Settings.THROTTLE_OUTGOING_PACKETS == false ||
                type == PacketType.PacketAck ||
                type == PacketType.LogoutRequest)
            {
                SendPacketFinal(outgoingPacket);
            }
            else
            {
                Network.PacketOutbox.Enqueue(outgoingPacket);
            }

            #endregion Queue or Send

            #region Stats Tracking
            if (Client.Settings.TRACK_UTILIZATION)
            {
                Client.Stats.Update(type.ToString(), OpenMetaverse.Stats.Type.Packet, dataLength, 0);
            }
            #endregion
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:48,代码来源:Simulator.cs

示例5: PacketSent

 protected override void PacketSent(UDPPacketBuffer buffer, int bytesSent)
 {
     // Stats tracking
     Interlocked.Add(ref Stats.SentBytes, bytesSent);
     Interlocked.Increment(ref Stats.SentPackets);
     
     Client.Network.RaisePacketSentEvent(buffer.Data, bytesSent, this);
 }
开发者ID:RavenB,项目名称:gridsearch,代码行数:8,代码来源:Simulator.cs

示例6: PacketSent

 protected abstract void PacketSent(UDPPacketBuffer buffer, int bytesSent);
开发者ID:3di,项目名称:3di-viewer-rei-libs,代码行数:1,代码来源:UDPBase.cs

示例7: AsyncBeginSend

        public void AsyncBeginSend(UDPPacketBuffer buf)
        {
            rwLock.AcquireReaderLock(-1);

            if (!shutdownFlag)
            {
                try
                {
                    Interlocked.Increment(ref rwOperationCount);
                    udpSocket.BeginSendTo(
                        buf.Data,
                        0,
                        buf.DataLength,
                        SocketFlags.None,
                        buf.RemoteEndPoint,
                        new AsyncCallback(AsyncEndSend),
                        buf);
                }
                catch (SocketException)
                {
                    //Logger.Log(
                    //    "A SocketException occurred in UDPServer.AsyncBeginSend()",
                    //    Helpers.LogLevel.Error, se);
                }
            }

            rwLock.ReleaseReaderLock();
        }
开发者ID:3di,项目名称:3di-viewer-rei-libs,代码行数:28,代码来源:UDPBase.cs

示例8: SendAckImmediate

        public virtual void SendAckImmediate(IPEndPoint remoteEndpoint, PacketAckPacket ack)
        {
            byte[] packetData = ack.ToBytes();
            int length = packetData.Length;

            UDPPacketBuffer buffer = new UDPPacketBuffer(remoteEndpoint, length);
            buffer.DataLength = length;

            Buffer.BlockCopy(packetData, 0, buffer.Data, 0, length);

            AsyncBeginSend(buffer);
        }
开发者ID:JeffCost,项目名称:opensim,代码行数:12,代码来源:LLUDPServer.cs

示例9: SendAckImmediate

        private void SendAckImmediate(IPEndPoint remoteEndpoint, uint sequenceNumber)
        {
            PacketAckPacket ack = new PacketAckPacket();
            ack.Header.Reliable = false;
            ack.Packets = new PacketAckPacket.PacketsBlock[1];
            ack.Packets[0] = new PacketAckPacket.PacketsBlock();
            ack.Packets[0].ID = sequenceNumber;

            byte[] packetData = ack.ToBytes();
            int length = packetData.Length;

            UDPPacketBuffer buffer = new UDPPacketBuffer(remoteEndpoint, length);
            buffer.DataLength = length;

            Buffer.BlockCopy(packetData, 0, buffer.Data, 0, length);

            //            AsyncBeginSend(buffer);
            SyncSend(buffer);

        }
开发者ID:HGExchange,项目名称:Aurora-Sim,代码行数:20,代码来源:LLUDPServer.cs

示例10: AsyncBeginReceive

        private void AsyncBeginReceive()
        {
            // allocate a packet buffer
            //WrappedObject<UDPPacketBuffer> wrappedBuffer = Pool.CheckOut();
            UDPPacketBuffer buf = new UDPPacketBuffer();

            if (!m_shutdownFlag)
            {
                try
                {
                    // kick off an async read
                    m_udpSocket.BeginReceiveFrom(
                        //wrappedBuffer.Instance.Data,
                        buf.Data,
                        0,
                        UDPPacketBuffer.BUFFER_SIZE,
                        SocketFlags.None,
                        ref buf.RemoteEndPoint,
                        AsyncEndReceive,
                        //wrappedBuffer);
                        buf);
                }
                catch (SocketException e)
                {
                    if (e.SocketErrorCode == SocketError.ConnectionReset)
                    {
                        m_log.Warn("[UDPBASE]: SIO_UDP_CONNRESET was ignored, attempting to salvage the UDP listener on port " + m_udpPort);
                        bool salvaged = false;
                        while (!salvaged)
                        {
                            try
                            {
                                m_udpSocket.BeginReceiveFrom(
                                    //wrappedBuffer.Instance.Data,
                                    buf.Data,
                                    0,
                                    UDPPacketBuffer.BUFFER_SIZE,
                                    SocketFlags.None,
                                    ref buf.RemoteEndPoint,
                                    AsyncEndReceive,
                                    //wrappedBuffer);
                                    buf);
                                salvaged = true;
                            }
                            catch (SocketException) { }
                            catch (ObjectDisposedException) { return; }
                        }

                        m_log.Warn("[UDPBASE]: Salvaged the UDP listener on port " + m_udpPort);
                    }
                }
                catch (ObjectDisposedException) { }
            }
        }
开发者ID:rknop,项目名称:Aurora-Sim,代码行数:54,代码来源:OpenSimUDPBase.cs

示例11: PacketBuildingFinished

 /// <summary>
 /// Called when the packet is built and this buffer is no longer in use
 /// </summary>
 /// <param name="buffer"></param>
 protected void PacketBuildingFinished(UDPPacketBuffer buffer)
 {
     buffer.ResetEndpoint();
     _recvBufferPool.ReturnObject(buffer);
 }
开发者ID:emperorstarfinder,项目名称:halcyon,代码行数:9,代码来源:OpenSimUDPBase.cs

示例12: SendPacketData

        public void SendPacketData(byte[] data, int dataLength, PacketType type, bool doZerocode)
        {
            UDPPacketBuffer buffer = new UDPPacketBuffer(remoteEndPoint, Packet.MTU);

            // Zerocode if needed
            if (doZerocode)
            {
                try { dataLength = Helpers.ZeroEncode(data, dataLength, buffer.Data); }
                catch (IndexOutOfRangeException)
                {
                    // The packet grew larger than Packet.MTU bytes while zerocoding.
                    // Remove the MSG_ZEROCODED flag and send the unencoded data
                    // instead
                    data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
                    Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
                }
            }
            else
            {
                Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
            }
            buffer.DataLength = dataLength;

            #region Queue or Send

            NetworkManager.OutgoingPacket outgoingPacket = new NetworkManager.OutgoingPacket(this, buffer);

            // Send ACK and logout packets directly, everything else goes through the queue
            if (Network.ThrottleOutgoingPackets == false ||
                type == PacketType.PacketAck ||
                type == PacketType.LogoutRequest)
            {
                SendPacketFinal(outgoingPacket);
            }
            else
            {
                Network.PacketOutbox.Enqueue(outgoingPacket);
            }

            #endregion Queue or Send
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:41,代码来源:Simulator.cs

示例13: AsyncBeginSend

 public void AsyncBeginSend(UDPPacketBuffer buf)
 {
     if (!m_shutdownFlag)
     {
         try
         {
             m_udpSocket.BeginSendTo(
                 buf.Data,
                 0,
                 buf.DataLength,
                 SocketFlags.None,
                 buf.RemoteEndPoint,
                 AsyncEndSend,
                 buf);
         }
         catch (SocketException) { }
         catch (ObjectDisposedException) { }
     }
 }
开发者ID:AlphaStaxLLC,项目名称:taiga,代码行数:19,代码来源:OpenSimUDPBase.cs

示例14: OutgoingPacket

 public OutgoingPacket(Simulator simulator, UDPPacketBuffer buffer, PacketType type)
 {
     Simulator = simulator;
     Buffer = buffer;
     this.Type = type;
 }
开发者ID:TooheyPaneer,项目名称:libopenmetaverse,代码行数:6,代码来源:NetworkManager.cs

示例15: SendPacketData

        public void SendPacketData(LLUDPClient udpClient, byte[] data, Packet packet, ThrottleOutPacketType category, UnackedPacketMethod resendMethod, UnackedPacketMethod finishedMethod)
        {
            int dataLength = data.Length;
            bool doZerocode = (data[0] & Helpers.MSG_ZEROCODED) != 0;
            bool doCopy = true;

            // Frequency analysis of outgoing packet sizes shows a large clump of packets at each end of the spectrum.
            // The vast majority of packets are less than 200 bytes, although due to asset transfers and packet splitting
            // there are a decent number of packets in the 1000-1140 byte range. We allocate one of two sizes of data here
            // to accomodate for both common scenarios and provide ample room for ACK appending in both
            int bufferSize = dataLength * 2;

            UDPPacketBuffer buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);

            // Zerocode if needed
            if (doZerocode)
            {
                try
                {
                    dataLength = Helpers.ZeroEncode(data, dataLength, buffer.Data);
                    doCopy = false;
                }
                catch (IndexOutOfRangeException)
                {
                    // The packet grew larger than the bufferSize while zerocoding.
                    // Remove the MSG_ZEROCODED flag and send the unencoded data
                    // instead
                    m_log.Info("[LLUDPSERVER]: Packet exceeded buffer size during zerocoding for " + packet.Type + ". DataLength=" + dataLength +
                        " and BufferLength=" + buffer.Data.Length + ". Removing MSG_ZEROCODED flag");
                    data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
                }
            }

            // If the packet data wasn't already copied during zerocoding, copy it now
            if (doCopy)
            {
                if (dataLength <= buffer.Data.Length)
                {
                    Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
                }
                else
                {
                    bufferSize = dataLength;
                    buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);

                    // m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" +
                    //     type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet");
                    Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
                }
            }

            buffer.DataLength = dataLength;

            #region Queue or Send

            OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, resendMethod, finishedMethod, packet);

            if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket))
                SendPacketFinal(outgoingPacket);

            #endregion Queue or Send
        }
开发者ID:HGExchange,项目名称:Aurora-Sim,代码行数:62,代码来源:LLUDPServer.cs


注:本文中的UDPPacketBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。