public void OnMyReceived(Connection connection, byte[] buffer, int offset, int size)
        {
            if (size == -1)
            {
                LogU.Debug(" frameDecoder Decode failed then reConnect");
                connection.Disconnect(true);
                clientCore.reConnect();
                return;
            }


            Message msg = clientCore.Serializer.Deserialize(buffer, offset, size);

            clientCore.handlerMgr.handle(msg);
        }
Example #2
0
        public bool SendToGame <T>(T message, int msgId)
        {
            if (connection == null)
            {
                return(false);
            }

            int netStatus = connection.getStatus();

            //无论什么原因导致连接断开,只要需要发送数据,并且已经初始化过,那么就尝试重连
            if (netStatus == NHNet.CON_CLOSED)
            {
                if (connection.HasInit())
                {
                    clientCore.reConnect();
                    LogU.Debug("Transmitter: NHNet.CON_CLOSED ,has try reConnect,this msg can not send");
                    return(false);
                }
            }
            if (netStatus == NHNet.CON_CONNECTING)
            {
                LogU.Debug("Transmitter:  NHNet.CON_CONNECTING ,can not send data");
                return(false);
            }

            int  length = 0;
            bool result = ClientCore.Serializer.Serialize <T>(ref buffer, ref length, message, msgId, ClientCore.accountId);

            if (result)
            {
                result = connection.Send(buffer, 0, length);
            }
            else
            {
                LogU.Error("Failed to serialize the message {0}", msgId);
            }

            return(result);
        }