It took 10 sec delay to receive message on web page that websocket server "connection closed", I need faster update about server connection.

Jan 22, 2015 at 8:35 PM

I have developed a basic console web application using SuperWebSocket. When one runs it on web browser,it shows three buttons
Initially when I tried connect and disconnect operations,It was updating connection status(Connection open or connection close) to user on web browser immediately.

I have done data transfer between Web app and WebSocket server,but after closing connection, it took 10 sec to update user that "Connection closed". I want to show this "Connection closed" message as soon as data transmission is finished without any delay.
Following is the code for for all kind of suggessions and modifications
Thanks in advance.
<head> <meta charset="UTF-8"> <!-- kodierungsart doit etre ds les premiers 1024 byte--> <title>lol</title> <!--ce titre apparait ds la description de la fenêtre --> <link rel="stylesheet" type="text/css" href="style.css" /> <link rel="stylesheet" type="text/css" href="style1.css" /> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> var noSupportMessage = "Your browser cannot support WebSocket!"; var ws; function appendMessage(message) { $('#serverStatus').append(message); } function connectSocketServer() { var support = "MozWebSocket" in window ? 'MozWebSocket' : ("WebSocket" in window ? 'WebSocket' : null); if (support == null) { appendMessage("* " + noSupportMessage + "<br/>"); return; } appendMessage("* Connecting to server ..<br/>"); // create a new websocket and connect ws = new window[support]('ws://'); // when data is comming from the server, this metod is called ws.onmessage = function (evt) { var donnees = // alert(donnes); var results = donnees.split('$'); for (var j = 0; j < 10; j++) { var result = results[j].split(';'); switch (result[0]) { case "Z1": { for (var i = 1; i < result.length; i++) { var tabdaten = document.getElementById("Z1" + (i - 1)).innerHTML = (result[i]); } } break; case "Z2": { for (var i = 1; i < result.length; i++) { var tabdaten = document.getElementById("Z2" + (i - 1)).innerHTML = (result[i]); } } break; default: } } }; // when the connection is established, this method is called ws.onopen = function () { appendMessage('* Connection open<br/>'); $('#pswd').attr("disabled", ""); $('#sendButton').attr("disabled", ""); $('#connectButton').attr("disabled", "disabled"); $('#disconnectButton').attr("disabled", ""); }; // when the connection is closed, this method is called ws.onclose = function () { appendMessage('* Connection closed<br/>'); $('#pswd').attr("disabled", "disabled"); $('#sendButton').attr("disabled", "disabled"); $('#connectButton').attr("disabled", ""); $('#disconnectButton').attr("disabled", "disabled"); } } function sendMessage() { if (ws) { var messageBox = document.getElementById('pswd'); ws.send(messageBox.value); messageBox.value = ""; } } function disconnectWebSocket() { if (ws) { ws.close(); } } function connectWebSocket() { connectSocketServer(); } window.onload = function () { $('#pswd').attr("disabled", "disabled"); $('#sendButton').attr("disabled", "disabled"); $('#disconnectButton').attr("disabled", "disabled"); } </script> </head> <body>
<div class="ui-grid-a"> <div class="ui-block-a"> <input type="button" id="connectButton" value="connect" onclick="connectWebSocket()" /> </div> <div class="ui-block-b"> <input type="button" id="disconnectButton" value="disconnect" onclick="disconnectWebSocket()" /> </div> </div>
            <div class="ui-grid-a">

                <div class="ui-block-a">
                 <input type="password" name="passw" id="pswd" placeholder="Password" style="height:43px;">

                <div class="ui-block-b">
                 <input type="button" id="sendButton" value="start" onclick="sendMessage()" />
<div id= content2> <table id="mytab"> <thead> <tr><th>id</th><th>value</th><th>unit</th></tr> </thead> <tbody id="body"> <tr id="Zeile1"><td id="Z10"></td><td id="Z11"></td><td id="Z12"></td></tr> <tr id="Zeile2"><td id="Z20"></td><td id="Z21"></td><td id="Z22"></td></tr> <tr id="Zeile3"><td id="Z30"></td><td id="Z31"></td><td id="Z32"></td></tr> <tr id="Zeile4"><td id="Z40"></td><td id="Z41"></td><td id="Z42"></td></tr> </tbody> </table> </div>
        <div id="serverStatus">
Jan 28, 2015 at 3:29 AM
I have no idea about this issue. Probably you can debug it by Wireshark.