I've observed in my application server log that, in a space of 15 seconds, two live connections are made from the same client (from the same page, i'm sure of this because of the design of my app) and message are sent using both these connections. Both connections use websocket protocols. I have two questions.
first, is this even possible? I thought sockjs only allow one live connection per page.
second, based on my front-end javascript logic, it seems impossible that two live connections can be established:
var conn = null;
var retry = null;
...
function connect() {
disconnect();
var options = ...
conn.onopen = function() {
...
};
conn.onmessage = function(e) {
...
};
conn.onclose = function() {
conn = null;
window.clearTimeout(retry);
retry = window.setTimeout(connect, 3000));
window.alert("connection problem!");
}
function disconnect() {
if (conn !== null) {
conn.close();
conn = null;
}
}
Given the call to disconnect() at the beginning of connect() and how re-connection works in onclose callback, there should be only one connection made at any point of time. However, the server-side log clearly shows that two websocket connections are made from the same page within 15 seconds - one is made while the other is still open.
what is going on here?!