420 CHAPTER 10 WebSocket communications
When the webpage is displayed using Internet Explorer 10, a message is displayed stating,
WebSockets Supported! The CONNECTED message is displayed when the connection is open.
If a message is entered and the Send button is clicked, the message is sent to the server, and
the response is displayed, as shown in Figure 10-1.
FIGURE 10-1 he completed WebSocket test pageT
Dealing with timeouts
One of the problems you might encounter is that the server might time out your connection
after a period of inactivity. You might also have firewalls between your browser and the server
that can time out your connection. In many cases, an error is triggered without an associated
message. You can identify timeout errors by not triggering any activity for up to 20 minutes.
You might see that you consistently get timeouts after only 30 seconds. Although it’s rela-
tively new, the W3C draft for WebSocket does not address timeouts.
One way of dealing with timeouts is to send an empty message to the server periodically.
The completed default.js file provides an example of periodically sending an empty message,
as follows.
/// <reference path="_references.js" />
var wsUri = 'ws://echo.websocket.org/';
var webSocket;
var timerId = 0;
$(document).ready(function () {
if (checkSupported()) {
connect();
$('#btnSend').click(doSend);
}
});