コード例 #1
0
        /// <summary>
        /// 通过TCP协议发送
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="messageId"></param>
        /// <param name="data"></param>
        public void SendTcp <T>(ClientID clientID, MessageID id, T data) where T : class, ProtoBuf.IExtensible
        {
            var client = GetClient(clientID);

            if (client == null)
            {
                return;
            }

            byte[] bytes = ProtoTransfer.SerializeProtoBuf <T>(data);

            MessageBuffer buffer = new MessageBuffer((int)id, bytes, client.acceptSock);

            client.SendTcp(buffer);
        }
コード例 #2
0
        public static void Dispatch(MessageBuffer message)
        {
            if (message == null)
            {
                return;
            }
            int id = message.id();

            Type type = GetType((MessageID)id);

            if (type == null)
            {
                return;
            }

            object data = ProtoTransfer.DeserializeProtoBuf(message.body(), type);

            if (data == null)
            {
                return;
            }

            mDispatcher.Dispatch(id, data, type);
        }