I've a little problem in sendine my messages to the server. It probably send them and the server recieve them, but i have no real idea how to mask them correctly. I know this is actually the way: http://tools.ietf.org/html/rfc6455#section-5.2 But I'm not understanding a lot of it. It would be nice if someone could share a whole pseudocode what actually need to be done from the plain message until the writing into the buffer. I also searched here a lot for information but mostly they advice libs or directly the link. The problem is that libs are nice, but i've actually done already all i need. Only the sending mask is missing.
Regards
Can you send the message with mask bit off?
When mask bit is set, the server expect 4 bytes mask to present, and the payload is XOR'd with
for ( size_t i=0; i<packet_len; i++ ) {
packet[i] = payload[i] ^ mask_bits[i&3];
}
EDIT: Adding more detail.
I assume you have done the Upgrade handshake, the actual bytes to send to network for communication are:
[flag][mask_bit, len][extended length][mask][payload]
Where:
For example, to send "Hello" to server in binary mode, you do:
The masked payload is: 0x48^0x11, 0x65^0x22, 0x6C^0x33, 0x6C^0x44, 0x6F^0x11, 0x00^0x22 => 0x59, 0x47, 0x5F, 0x28, 0x7E, 0x22
The whole stream is: 0x82, 0x86, 0x11, 0x22, 0x33, 0x44, 0x59, 0x47, 0x5F, 0x28, 0x7E, 0x22
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.