コード例 #1
0
 public void EnqueuePacketSend(ArrByte64K arrByte64K)
 {
     lock (QueSendArrByte64Ks)
     {
         QueSendArrByte64Ks.Enqueue(arrByte64K);
     }
 }
コード例 #2
0
        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="pkt">PacketSend</param>
        public void Send(ArrByte64K arrByte64K)
        {
            if (!CheckSocketState())
            {
                DisconnectedHandler(StatusCode.Disconnect);
                return;
            }


            ArrByte64K arrByte = arrByte64K;// pkt.ExportArrByte64K();

            try
            {
                clientSocket.BeginSend(arrByte.arrByte64K, 0, arrByte.len, 0, new AsyncCallback(SendCallback), clientSocket);
                if (!sendDone.WaitOne(Timeoutmilliseconds))
                {
                    TimeOut(StatusCode.TimeoutDisconnect);
                }
                Receive(clientSocket);
            }
            catch (Exception e)
            {
                SockErrorStr = e.ToString();
                DisconnectedHandler(StatusCode.Disconnect);
                //Console.WriteLine(e.ToString());
            }
        }
コード例 #3
0
 public void SetArrByte(ArrByte64K arrByte)
 {
     _arrByte = arrByte;
     _readLen = 0;//默认从第byte[0]读取数据
     if (_arrByte != null)
     {
         _arrByte.len = (ushort)(_arrByte.arrByte64K[0] * 256 + _arrByte.arrByte64K[1]);
     }
 }
コード例 #4
0
        public ArrByte64K ExportArrByte64K()
        {
            _arrByte64K.arrByte64K[0] = (byte)((_i) >> 8);
            _arrByte64K.arrByte64K[1] = (byte)((_i));//0,1字节存储字节流的长度
            _arrByte64K.len           = _i;
            var ar = _arrByte64K;

            _arrByte64K = null;
            return(ar);
        }
コード例 #5
0
 private ServerPacket(ArrByte64K arrByte64K)
 {
     arrByteReader = new ArrByteReader();
     arrByteReader.SetArrByte(arrByte64K);
     len        = arrByteReader.ReaduShort();
     CType      = (CodeType)arrByteReader.ReadByte();
     Code       = arrByteReader.ReadByte();
     ReturnCode = arrByteReader.ReadShort();
     Console.WriteLine("length = {0},CodeType={1} Code = {2}", len, CType, Code);
 }
コード例 #6
0
        /// <summary>
        /// 处理接收到的数据
        /// </summary>
        private void ReceiveHandler()
        {
            int len = _receiveByte64K.arrByte64K[0] * 256 + _receiveByte64K.arrByte64K[1];

            if (len > 0 && _receiveByte64K.len >= len)
            {
                ArrByte64K bytes64k = ArrByte64K.Create();
                bytes64k.AppendBytes(_receiveByte64K.arrByte64K, len);
                _receiveByte64K.DelBytes((ushort)len);
                //ServerPacket serPkt = ServerPacket.Create(bytes64k);
                //App_Event.HandleEvent(serPkt);
                if (Peer.PeerListener != null)
                {
                    ServerPacket serverPacket = ServerPacket.Create(bytes64k);
                    PeerTool.DistributePeer(serverPacket, Peer);
                }
            }
        }
コード例 #7
0
 public static ArrByte64K Create(ArrByte64K bytes64k)
 {
     return(new ArrByte64K(bytes64k));
 }
コード例 #8
0
 public ArrByte64K(ArrByte64K bytes64k)
 {
     Array.Copy(bytes64k.arrByte64K, 0, arrByte64K, 0, bytes64k.arrByte64K.Length);
 }
コード例 #9
0
        private ushort _i = 3;// 3 个字节开始存储数据

        private PacketSend()
        {
            _arrByte64K = new ArrByte64K();
        }
コード例 #10
0
        }                                                //= new ArrByteReader();

        public static ServerPacket Create(ArrByte64K arrByte64K)
        {
            return(new ServerPacket(arrByte64K));
        }