// From index.htm
function WebSocketTest()
{
if ("WebSocket" in window)
{
// Let us open a web socket
var ws = new WebSocket("ws://<!--VARIABLE IPCAST(GetSocketLocalAddr4(fd)) -->/echo");
ws.onopen = function()
{
// Web Socket is connected, send data using send()
setInterval(function sendMsg() {ws.send("Message to send")}, 1000);
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
};
ws.onclose = function()
{
// websocket is closed.
};
}
else
{
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}
The problem is that read() function in UserMain() while loop sometimes returns incomplete message (namely "Message is sen"). Wireshark failing to recognize this TCP packet as a WebSocket message. The only difference with the normal one is absence of last byte. Even WS payload length (second byte in TCP payload) is still equals to 15 which is incorrect. Chrome's Developer Tools shows this outgoing message have been sent without any deformation.
Are you capturing the WebSocket handshake in your Wireshark capture? If not, Wireshark won't recognize the packets as WebSocket packets but TCP packets instead.
Is the whole message (WebSocket payload) and length correct in the packets that Wireshark captures?
just like tcp.... chars are guarenteed to be correct and in order, but not grouped in any particular way...
After you read your partial message my guess is if you read again youll get the missing parts..
Yes, I'm starting packet capture before opening WebSocket and Wireshark recognizes most of the WS messages, and their payload and length are correct.
Maybe it has to do with some TCP optimization algorithm (Nagle?), I've tried NB::WebSocket::ws_setoption(ws_fd, SO_NONAGLE); but it seems not helping much. It's kinda bad that I have to wait 1 second for next packet to get that last char to complete previous message. BTW I've noticed that only one last char can be clipped, so its always either
The problem is that I'm getting wrong WebSocket header: header says that the payload length is N and the FIN bit is set, but actual payload length is N -1. I'll get this last byte only with next frame. But I can't even know that the message I'm receiving is incomplete because of the FIN = 1.
Say I need to read messages from client every 10 seconds. When this fragmentation occurs, I'll wait for last byte 10 seconds, cause it will be received only with next client's message. Thus, it will be 20 seconds for one message in total, when it should be 10.