/// <summary>
        /// 发送SOCKET消息
        /// </summary>
        public void SendMessage(IMessage obj)
        {
            if (!ProtoDic.ContainProtoType(obj.GetType()))
            {
                Debug.LogError("不存协议类型");
                return;
            }
            ByteBuffer buff    = new ByteBuffer();
            int        protoId = ProtoDic.GetProtoIdByProtoType(obj.GetType());

            byte[] result;
            using (MemoryStream ms = new MemoryStream())
            {
                obj.WriteTo(ms);
                result = ms.ToArray();
            }

            UInt16 lengh = (UInt16)(result.Length + 2);

            Debug.Log("lengh" + lengh + ",protoId" + protoId);
            buff.WriteShort((UInt16)lengh);

            buff.WriteShort((UInt16)protoId);
            buff.WriteBytes(result);
            SendMessage(buff);
        }
Beispiel #2
0
        /// <summary>
        /// 소켓 메세지 보내기
        /// </summary>
        public void SendMessage(IMessage obj)
        {
            if (false == socketClient.IsConnected())
            {
                // block
                socketClient.SendSyncConnect();
            }

            if (!ProtoDic.ContainProtoType(obj.GetType()))
            {
                Debug.LogError("알 수 없는 프로토콜 유형");
                return;
            }
            ByteBuffer buff    = new ByteBuffer();
            int        protoId = ProtoDic.GetProtoIdByProtoType(obj.GetType());

            byte[] result;
            using (MemoryStream ms = new MemoryStream())
            {
                obj.WriteTo(ms);
                result = ms.ToArray();
            }

            UInt16 lengh = (UInt16)(result.Length + 2);

            Debug.Log("lengh" + lengh + ",protoId" + protoId);
            buff.WriteShort((UInt16)lengh);

            buff.WriteShort((UInt16)protoId);
            buff.WriteBytes(result);
            SendMessage(buff);
        }
Beispiel #3
0
        /// <summary>
        /// 发送SOCKET消息
        /// </summary>
        public void SendMessage(object obj)
        {
            if (!ProtoDic.ContainProtoType(obj.GetType()))
            {
                Debug.LogError("不存协议类型");
                return;
            }
            ByteBuffer buff    = new ByteBuffer();
            int        protoId = ProtoDic.GetProtoIdByProtoType(obj.GetType());

            buff.WriteShort((ushort)protoId);
            MemoryStream ms = new MemoryStream();

            ProtoBuf.Serializer.Serialize(ms, obj);
            byte[] result = ms.ToArray();
            buff.WriteBytes(result);
            SendMessage(buff);
        }