Beispiel #1
0
        public void Send(PacketSend pkt)
        {
            if (!CheckSocketState())
            {
                DisconnectedHandler();
                return;
            }


            ArrByte64K arrByte = pkt.ExportArrByte64K();

            try
            {
                clientSocket.BeginSend(arrByte.arrByte64K, 0, arrByte.len, 0, new AsyncCallback(SendCallback), clientSocket);
                if (!sendDone.WaitOne(Timeoutmilliseconds))
                {
                    TimeOut();
                }
                Receive(clientSocket);
            }
            catch (Exception e)
            {
                SockErrorStr = e.ToString();
                DisconnectedHandler();
                //Console.WriteLine(e.ToString());
            }
        }
Beispiel #2
0
 public void SetArrByte(ArrByte64K arrByte)
 {
     // Array.Copy(_arrByte.arrByte64K, arrByte.arrByte64K, arrByte.arrByte64K.Length);
     _arrByte = arrByte;
     _readLen = 4;//默认从第byte[4]读取数据
     if (_arrByte != null)
     {
         _arrByte.len = (ushort)(_arrByte.arrByte64K[0] * 256 + _arrByte.arrByte64K[1]);
     }
 }
Beispiel #3
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);
        }
Beispiel #4
0
 private ServerPacket(ArrByte64K arrByte64K)
 {
     //int offset = 0;
     //ushort count;
     len     = (ushort)(arrByte64K.arrByte64K[0] * 256 + arrByte64K.arrByte64K[1]);
     eventId = (ushort)(arrByte64K.arrByte64K[2] * 256 + arrByte64K.arrByte64K[3]);
     Console.WriteLine("length = {0}, eventId = {1}", len, eventId);
     //ArrByte64K arr64k = new ArrByte64K();
     arrByteReader.SetArrByte(arrByte64K);
 }
Beispiel #5
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);
            }
        }
Beispiel #6
0
 public static ArrByte64K Create(ArrByte64K bytes64k)
 {
     return(new ArrByte64K(bytes64k));
 }
Beispiel #7
0
 public ArrByte64K(ArrByte64K bytes64k)
 {
     Array.Copy(bytes64k.arrByte64K, 0, arrByte64K, 0, bytes64k.arrByte64K.Length);
 }
Beispiel #8
0
 public static ServerPacket Create(ArrByte64K arrByte64K)
 {
     return(new ServerPacket(arrByte64K));
 }
Beispiel #9
0
 private PacketSend()
 {
     _arrByte64K = new ArrByte64K();
 }