Esempio n. 1
0
        public void Send(Cmd4Send cmd)
        {
            ClientSendBuffer.Clear();
            ClientSendBuffer.PutShort(MSG_HEAD);
            byte[] content = cmd.Encode();
            int    len     = content.Length + 2;//+2是cmd的short长度

            ClientSendBuffer.PutInt(len);
            ClientSendBuffer.PutShort(cmd.Cmd);
            ClientSendBuffer.PutBytes(content);
            byte[] bs = ClientSendBuffer.ToArray();

            //Debug.Log("发送长度:"+bs.Length);

            //IoBuffer ib = new IoBuffer(102400);
            //ib.PutBytes(bs);
            //short head = ib.GetShort();
            //int len0 = ib.GetInt();
            //int cmd0 = ib.GetShort();
            //int contentI = ib.GetInt();
            //string contentS = ib.GetString();
            //Debug.Log("head:"+head+" len0:"+len0+" cmd0:"+cmd0+" contentI:"+contentI+" contentS:"+contentS);

            Send(bs);
        }
Esempio n. 2
0
        public void Send(string sessionID, Cmd4Send cmd)
        {
            Debug.Log("服务端向sessionID:" + sessionID + " 发送 cmd:" + cmd.Cmd);

            if (SessionDic.ContainsKey(sessionID))
            {
                ServerSendBuffer.Clear();
                ServerSendBuffer.PutShort(MSG_HEAD);
                byte[] content = cmd.Encode();
                int    len     = content.Length + 2;//+2是cmd的short长度
                ServerSendBuffer.PutInt(len);
                ServerSendBuffer.PutShort(cmd.Cmd);
                ServerSendBuffer.PutBytes(content);
                byte[] bs = ServerSendBuffer.ToArray();
                AsyncSend(SessionDic[sessionID]._SocketPackMgr._Socket, bs);
            }
        }