C - websocket - recv reads more than payload length -


i building websocket server in c. right following rfc6455 specification , have managed far implementing chat protocol, such connected clients can send messages each other. test strength of server ran piece of javascript test if handle several messages same client per second:

i = ''; = 0; t = setinterval('a++; += "...................................................................................................."; dosend(a + i);', 20); 

what code above send message each 20 ms. furthermore message sent, 100 bytes larger every message. server manage messages , send connected clients first 360 times, weird happened.

for every message server receives, takes payload length of it, message 360 360*100+3 = 36003. value given in first part of message , rely on message 36003 bytes long.

i use function recv receive data socket connection , right have buffer size of 8192 bytes. when receive message larger buffer size, call recv once again until whole message received. weird thing when receive message number 360, should read buffer 5 times (5*8192 > 40000) receive whole message. instead of read number 5 being 3235 bytes (36003-(4*8192)) recv function returns full buffer aka. 8192 bytes. have clue going on?

@simonc right, when messages received quick merge same message received recv. i'll have split messages received recv multiple messages, if buffer longer expected. thank much! :)


Comments