Example #1
0
        public override void Receive(byte[] data, int startIndex, int length)
        {
            var strippedData = new byte[length];

            Array.Copy(data, startIndex, strippedData, 0, length);
            _receiveQueue.Enqueue(strippedData);
        }
        public override void Receive(byte[] data, int startIndex, int length)
        {
            var    processedLength = 0;
            ushort sequenceNumber;
            var    copiedData = new byte[length];

            Array.Copy(data, startIndex, copiedData, 0, length);

            if (_sendAcks && copiedData[0] == 0xff && copiedData[1] == 0xff)
            {
                lock (_outboxLock)
                {
                    sequenceNumber = BitConverter.ToUInt16(copiedData, 2);
                    _outbox.Remove(sequenceNumber);
                }
                return;
            }
            sequenceNumber   = BitConverter.ToUInt16(copiedData, 0);
            processedLength += sizeof(ushort);
            if (_inbox.ContainsKey(sequenceNumber) || _lastProcessedReceiveIndex >= sequenceNumber)
            {
                Debug.LogWarning("Got same sequence twice: " + sequenceNumber);
                return;
            }
            _inbox[sequenceNumber] = new InboxItem()
            {
                data = copiedData, startIndex = processedLength, length = length - processedLength
            };
            if (sequenceNumber > _lastReceiveIndex)
            {
                _lastReceiveIndex = sequenceNumber;
            }
            if (_sendAcks)
            {
                byte[] ackData = new byte[] { 0xff, 0xff, 0, 0 };
                Array.Copy(BitConverter.GetBytes(sequenceNumber), 0, ackData, 2, 2);
                Send(ackData);
                _pendingAcksQueue.Enqueue(sequenceNumber);
                ProcessOutbox();
            }
            ProcessInbox();
        }
Example #3
0
        public override void Receive(byte[] data, int startIndex, int length)
        {
            var    processedLength = 0;
            ushort sequenceNumber;

            if (_sendAcks && data[startIndex] == 0xff && data[startIndex + 1] == 0xff)
            {
                lock (_outboxLock)
                {
                    sequenceNumber = BitConverter.ToUInt16(data, startIndex + 2);
                    _outbox.Remove(sequenceNumber);
                }
                return;
            }
            sequenceNumber   = BitConverter.ToUInt16(data, startIndex);
            processedLength += sizeof(ushort);
            if (_inbox.ContainsKey(sequenceNumber))
            {
                Debug.LogWarning("Got same sequence twice: " + sequenceNumber);
            }
            //Debug.LogError("Add to inbox: " + Debugging.TeleportDebugUtils.DebugString(data, startIndex + processedLength, length - processedLength));
            _inbox[sequenceNumber] = new InboxItem()
            {
                data = data, startIndex = startIndex + processedLength, length = length - processedLength
            };
            if (sequenceNumber > _lastReceiveIndex)
            {
                _lastReceiveIndex = sequenceNumber;
            }
            if (_sendAcks)
            {
                byte[] ackData = new byte[] { 0xff, 0xff, 0, 0 };
                Array.Copy(BitConverter.GetBytes(sequenceNumber), 0, ackData, 2, 2);
                Send(ackData);
                _pendingAcksQueue.Enqueue(sequenceNumber);
                ProcessOutbox();
            }
            ProcessInbox();
        }
Example #4
0
 public override void Send(byte[] data)
 {
     _sendQueue.Enqueue(data);
 }