Exemple #1
0
        /// <summary>
        /// 收到消息
        /// </summary>
        /// <param name="br">流</param>
        /// <param name="socketID">套接字ID</param>
        /// <param name="localSID">本地套接字ID</param>
        /// <param name="len">长度</param>
        public virtual void onCallBack(FCBinary br, int socketID, int localSID, int len)
        {
            int headSize     = sizeof(int) * 4 + sizeof(short) * 3 + sizeof(byte) * 2;
            int functionID   = br.readShort();
            int sessionID    = br.readInt();
            int requestID    = br.readInt();
            int state        = br.readByte();
            int compressType = br.readByte();
            int bodyLength   = br.readInt();

            byte[] body = new byte[len - headSize];
            br.readBytes(body);
            if (compressType == COMPRESSTYPE_GZIP)
            {
                using (MemoryStream dms = new MemoryStream()) {
                    using (MemoryStream cms = new MemoryStream(body)) {
                        using (GZipStream gzip = new GZipStream(cms, CompressionMode.Decompress)) {
                            byte[] buffer = new byte[1024];
                            int    size   = 0;
                            while ((size = gzip.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                dms.Write(buffer, 0, size);
                            }
                            body = dms.ToArray();
                        }
                    }
                }
            }
            FCMessage message = new FCMessage(GroupID, ServiceID, functionID, sessionID, requestID, socketID, state, compressType, bodyLength, body);

            onReceive(message);
            onWaitMessageHandle(message);
            message.m_body = null;
            body           = null;
        }
Exemple #2
0
 /// <summary>
 /// 回调函数
 /// </summary>
 /// <param name="socketID">连接ID</param>
 /// <param name="localSID">本地连接ID</param>
 /// <param name="bytes">数据</param>
 /// <param name="len">长度</param>
 public static void callBack(int socketID, int localSID, byte[] bytes, int len)
 {
     m_downFlow += len;
     try {
         if (len > 4)
         {
             FCBinary br = new FCBinary();
             br.write(bytes, len);
             int head      = br.readInt();
             int groupID   = br.readShort();
             int serviceID = br.readShort();
             if (m_services.containsKey(serviceID))
             {
                 m_services.get(serviceID).onCallBack(br, socketID, localSID, len);
             }
             br.close();
         }
     } catch (Exception ex) {
         Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
     }
 }