Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTTClientPacket导致空异常 #1

Open
yintao666 opened this issue Apr 11, 2023 · 1 comment
Open

MQTTClientPacket导致空异常 #1

yintao666 opened this issue Apr 11, 2023 · 1 comment

Comments

@yintao666
Copy link

//MQTTParse中 Write函对ISession参数做了一些处理,但是MQTTClientPacke中调用直接传空,导致发送时异常,请问MQTTClientPacke中如何才能拿到ISession解决此报错呢
public void Write(MQTTMessage msg, Stream stream, ISession session)
{
IServer server = session.Server;
if (server.EnableLog(LogType.Debug))
{
server.Log(LogType.Debug, session, $"write mqtt message {msg}");
}

        MemoryStream protocolStream = GetProtocolStream();
        int num = 0;
        num |= (int)msg.Type << 4;
        if (msg.DUP)
        {
            num |= 8;
        }

        num |= (int)msg.QoS << 1;
        if (msg.Retain)
        {
            num |= 1;
        }

        stream.WriteByte((byte)num);
        msg.Write(protocolStream, session);
        if (server.EnableLog(LogType.Debug))
        {
            server.Log(LogType.Debug, session, $"write mqtt message body size {protocolStream.Length}");
        }

        mInt7BitHandler.Write(stream, (int)protocolStream.Length);
        protocolStream.Position = 0L;
        protocolStream.CopyTo(stream);
        if (server.EnableLog(LogType.Debug))
        {
            server.Log(LogType.Debug, session, "write mqtt message success");
        }
    }
}

MQTTClientPacket中加密部分中:
public void Encode(object data, IClient client, Stream stream)
{
MQTTMessage mQTTMessage = data as MQTTMessage;
if (mQTTMessage != null)
{
mMQTTParse.Write(mQTTMessage, stream.ToPipeStream(), null);
return;
}

        throw new BXException("Invalid message type!");
    }
@beetlex-io
Copy link
Owner

client是不存在session,你可以在MQTTParse添加一个iclient的参数,服务端传null就好。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants