I start script below in Firefox to connects and sends text message to Websocket server installed on my local computer. Can you explain me why firefox sometimes opens two different sockets on server side to do this task? (on second socket there is send 0-lentgh message).
<html>
<head>
<script>
function ws_connect()
{
ws = new WebSocket('ws://localhost:8080');
ws.binaryType = "arraybuffer";
ws.onopen = function(event)
{
var buf = new Uint8Array(2);
buf[0] = "hi".charCodeAt(0);
buf[1] = "hi".charCodeAt(1); // send message
ws.send(buf.buffer);
}
...
}
</script>
<script> window.onload = function() {ws_connect();};</script>
</head>
When I start script above , i get this expected data on server side(i print buffer, where first data from firefox is stored):
GET / HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pl,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://localhost:8383
Sec-WebSocket-Key: tEPJwmPYq9b2aMu7KfcpjQ==
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
When websocket handshake is ok, and script send "hi" massage, then firefox seems to open one more socket, send 0-length massage, and close it. (first socket is still open and i can use it.)