emqx / CocoaMQTT

MQTT 5.0 client library for iOS and macOS written in Swift
https://www.emqx.com/en
Other
1.57k stars 411 forks source link

Invalid header received by server #535

Open babaev-islom opened 12 months ago

babaev-islom commented 12 months ago

Hi, all. I'm using SDK version 2.1.5 and I ran into a problem.

I can connect normally by creating an instance and subscribing for callbacks.

The problem is whenever I send data via publish, data is sent to the server, yet connection closes immediately and I receive an error Error Domain=MGCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}.

Also, there are debug logs that are being printed to the console when I try to publish a message to a topic.

CocoaMQTT(debug): message.topic $TOPIC_NAME   = message.payload []
CocoaMQTT(debug): SEND: PUBLISH(id: 0, topic: $TOPIC_NAM payload: [])
CocoaMQTT(debug): ==========================MQTT 5.0==========================
CocoaMQTT(debug): packetFixedHeaderType 48
CocoaMQTT(debug): fixedHeader [48]
CocoaMQTT(debug): remainingLen(len: len) [51]
CocoaMQTT(debug): variableHeader [0, 19, 72, 105, 115, 116, 111, 114, 121, 47, 82, 101, 113, 117, 101, 115, 116, 47, 53, 49, 50, 29]
CocoaMQTT(debug): properties [1, 0, 8, 0, 15, 67, 111, 99, 111, 97, 77, 81, 84, 84, 53, 45, 84, 101, 115, 116, 9, 53, 38, 0, 4, 116, 114, 117, 101]
CocoaMQTT(debug): payload []
CocoaMQTT(debug): =============================================================
CocoaMQTT(debug): socket wrote data 0
CocoaMQTT(debug): socket disconnected
Optional(Error Domain=MGCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer})

I've paired with our backend mate and he has shown in logs that the server cannot parse the header.

Any clues what to look for? Am I doing something wrong?

leeway1208 commented 11 months ago

It means that the connection was refused by the broker. it is easier for the backend to see why it happened