Exemple #1
0
        public override void Send(DataPack dataPack)
        {
            var bytes = dataPack.ReadAllBytes();

            DataPackPool.Recycle(dataPack);
            _udpSocket.SendTo(bytes, 0, bytes.Length, SocketFlags.None, _remoteEndPoint);
        }
Exemple #2
0
        public void Send(int msgNum, byte[] bytes)
        {
            var pack = DataPackPool.GetDataPack(_initPostion, bytes);

            pack.TryAddDataToDict("VersionNum", -1, -1, _versionNum, typeof(int));
            pack.TryAddDataToDict("MsgNum", -1, -1, msgNum, typeof(int));
            pack.TryAddDataToDict("MsgBody", _initPostion, bytes.Length, null, null);
            OutPut(pack);
        }
Exemple #3
0
        public void Send <T>(int msgNum, T msgObj)
        {
            var sendedData = DataPackPool.GetDataPack();

            sendedData.TryAddDataToDict("VersionNum", -1, -1, _versionNum, typeof(int));
            sendedData.TryAddDataToDict("MsgBody", -1, -1, msgObj, typeof(T));
            sendedData.TryAddDataToDict("MsgNum", -1, -1, msgNum, typeof(int));
            OutPut(sendedData);
        }
Exemple #4
0
        public override void Send(DataPack dataPack)
        {
            var bytes = dataPack.ReadAllBytes();

            DataPackPool.Recycle(dataPack);
            if (_stream == null)
            {
                _stream = _tcpClient.GetStream();
            }
            _stream.Write(bytes, 0, bytes.Length);
        }
Exemple #5
0
 public KcpLayer(uint key)
 {
     _kcp = new KCP(key, (bytes, i) =>
     {
         var dataPack      = DataPackPool.GetDataPack(0, bytes, i);
         dataPack.Position = 0;
         OutPut(dataPack);
     });
     //_kcp.NoDelay(1, 10, 2, 1);
     //_kcp.WndSize(128, 128);
 }
Exemple #6
0
        private void HandleRecvQueue()
        {
            _recvQueue.Switch();
            while (!_recvQueue.Empty())
            {
                byte[] recvBufferRaw = _recvQueue.Pop();

                var dataPack = DataPackPool.GetDataPack(0, recvBufferRaw);
                dataPack.Position = 0;
                Recv(dataPack);
            }
        }
Exemple #7
0
        public override void Input(DataPack dataPack)
        {
            int ret = _kcp.Input(dataPack.ReadAllBytes());

            if (ret < 0)
            {
                Debug.LogError("Wrong KCP package");
                Recv(dataPack);
            }
            else
            {
                for (int size = _kcp.PeekSize(); size > 0; size = _kcp.PeekSize())
                {
                    var recvBuffer = new byte[size];
                    if (_kcp.Recv(recvBuffer) > 0)
                    {
                        var newPack = DataPackPool.GetDataPack(0, recvBuffer);
                        newPack.Position = 0;
                        Recv(newPack);
                    }
                }
            }
            dataPack.Recycle();
        }