socketio / socket.io-protocol

Socket.IO Protocol specification
https://socket.io
506 stars 62 forks source link

"strange" bytes at the beginning of each response #7

Closed pkyeck closed 10 years ago

pkyeck commented 10 years ago

handshake returns this:

00000000  00 01 01 01 ff 30 7b 22 73 69 64 22 3a 22 30 6a        0{"sid":"0j
00000010  57 4b 7a 6d 79 38 69 45 37 71 42 5a 49 4a 41 41   WKzmy8iE7qBZIJAA
00000020  41 65 22 2c 22 75 70 67 72 61 64 65 73 22 3a 5b   Ae","upgrades":[
00000030  22 77 65 62 73 6f 63 6b 65 74 22 2c 22 66 6c 61   "websocket","fla
00000040  73 68 73 6f 63 6b 65 74 22 5d 2c 22 70 69 6e 67   shsocket"],"ping
00000050  49 6e 74 65 72 76 61 6c 22 3a 32 35 30 30 30 2c   Interval":25000,
00000060  22 70 69 6e 67 54 69 6d 65 6f 75 74 22 3a 36 30   "pingTimeout":60
00000070  30 30 30 7d                                       000}   

event looks like this:

00000000  00 02 ff 34 30 00 02 07 ff 34 32 5b 22 65 76 65      40    42["eve
00000010  6e 74 22 2c 7b 22 73 6f 6d 65 22 3a 22 64 61 74   nt",{"some":"dat
00000020  61 22 7d 5d                                       a"}]      

where do they come from and why are they there? (payload?) do I have to split the response by 0xFF to get the packets?

thanks

pkyeck commented 10 years ago

btw: this is only the case while using polling. once the client switches to websocket everything looks good.

pkyeck commented 10 years ago

ok, found it.

/**
 * Encodes multiple messages (payload) as binary.
 *
 * <1 = binary, 0 = string><number from 0-9><number from 0-9>[...]<number
 * 255><data>
 *
 * Example:
 * 1 3 255 1 2 3, if the binary contents are interpreted as 8 bit integers
 *
 * @param {Array} packets
 * @return {Buffer} encoded payload
 * @api private
 */

exports.encodePayloadAsBinary = function (packets, callback) {
    // ...
}

should be mentioned here I think: https://github.com/LearnBoost/engine.io-protocol/blob/master/README.md instead of the [...] under "payload".

pkyeck commented 10 years ago

aargh, it was always there but wasn't displayed correctly :grimacing: