Beispiel #1
0
        /// <summary>
        /// 保持活跃
        /// </summary>
        /// <param name="socketID">套接字ID</param>
        /// <returns>状态</returns>
        public virtual int keepAlive(int socketID)
        {
            FCBinary bw = new FCBinary();

            bw.writeInt((int)4);
            byte[] bytes  = bw.getBytes();
            int    length = bytes.Length;
            int    ret    = FCClientSockets.send(socketID, bytes, length);

            bw.close();
            return(ret);
        }
Beispiel #2
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="message">消息</param>
        public virtual int send(FCMessage message)
        {
            FCBinary bw = new FCBinary();

            byte[] body          = message.m_body;
            int    bodyLength    = message.m_bodyLength;
            int    uncBodyLength = bodyLength;

            if (message.m_compressType == COMPRESSTYPE_GZIP)
            {
                using (MemoryStream cms = new MemoryStream()) {
                    using (GZipStream gzip = new GZipStream(cms, CompressionMode.Compress)) {
                        gzip.Write(body, 0, body.Length);
                    }
                    body       = cms.ToArray();
                    bodyLength = body.Length;
                }
            }
            int len = sizeof(int) * 4 + bodyLength + sizeof(short) * 3 + sizeof(byte) * 2;

            bw.writeInt(len);
            bw.writeShort((short)message.m_groupID);
            bw.writeShort((short)message.m_serviceID);
            bw.writeShort((short)message.m_functionID);
            bw.writeInt(message.m_sessionID);
            bw.writeInt(message.m_requestID);
            bw.writeByte((byte)message.m_state);
            bw.writeByte((byte)message.m_compressType);
            bw.writeInt(uncBodyLength);
            bw.writeBytes(body);
            byte[] bytes  = bw.getBytes();
            int    length = bytes.Length;
            int    ret    = FCClientSockets.send(message.m_socketID, bytes, length);

            m_upFlow += ret;
            bw.close();
            return(ret);
        }
Beispiel #3
0
 /// <summary>
 /// 发送消息
 /// </summary>
 /// <param name="socketID">套接字ID</param>
 /// <param name="str">数据</param>
 /// <param name="len">长度</param>
 /// <returns>状态</returns>
 public static int sendByClient(int socketID, byte[] str, int len)
 {
     return(FCClientSockets.send(socketID, str, len));
 }