Beispiel #1
0
 /// <summary>
 /// 回调函数
 /// </summary>
 /// <param name="socketID">连接ID</param>
 /// <param name="localSID">本地连接ID</param>
 /// <param name="str">数据</param>
 /// <param name="len">长度</param>
 public static void CallBack(int socketID, int localSID, IntPtr str, int len)
 {
     m_downFlow += len;
     try
     {
         if (len > 4)
         {
             byte[] bytes = GetValueChar(str, len);
             Binary br    = new Binary();
             br.Write(bytes, len);
             int         head      = br.ReadInt();
             int         groupID   = br.ReadShort();
             int         serviceID = br.ReadShort();
             BaseService service   = null;
             if (m_services.ContainsKey(serviceID))
             {
                 m_services[serviceID].OnCallBack(br, socketID, localSID, len);
             }
             br.Close();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
     }
 }
Beispiel #2
0
        public static int GetSecurities(List <Security> securities, int functionID, byte[] body, int bodyLength)
        {
            Binary binary = new Binary();

            binary.Write(body, bodyLength);
            int num = binary.ReadInt();

            if (num > 0)
            {
                for (int i = 0; i < num; i++)
                {
                    Security item = new Security();
                    item.m_code = binary.ReadString();

                    if (functionID == 0)
                    {
                        item.m_name    = binary.ReadString();
                        item.m_pingyin = binary.ReadString();
                        item.m_type    = binary.ReadShort();
                        item.m_status  = binary.ReadChar();
                    }
                    securities.Add(item);
                }
            }
            binary.Close();
            return(1);
        }
Beispiel #3
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(Binary 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();
                        }
                    }
                }
            }
            CMessage message = new CMessage(GroupID, ServiceID, functionID, sessionID, requestID, socketID, state, compressType, bodyLength, body);

            OnReceive(message);
            OnWaitMessageHandle(message);
            body = null;
        }