HTML and CSS Reference
In-Depth Information
ws.onopen=function () {
output("connected... ");
ws.onmessage=function (e) {
ws.onclose=function () {
output("Connection closed");
function send() {
var input=document.getElementById("input");
try {
} catch (e) {
function output(msg) {
var o=document.getElementById("output");
The onload event in the body element calls the connect() function. The connect() function creates
a WebSocket object and wires up the onOpen , onMessage , and onClose () event handlers. When the Send
Message button is clicked, the send() function is invoked. This gets the message from the text box and calls the
websocket's send() function. The output() function simply add the specified text to the pre element.
Testing the Initial Project
You now have a basic server application and a simple client. You'll test this now to make sure websocket is
working properly before adding the custom features.
eXerCISe 13-3. teStING the INItIaL appLICatION
In the Solution Explorer, right-click the Chapter 13 solution and select the “Set
StartUp projects” link.
In the dialog box, select the “Multiple startup projects” radio button. For both the
WsServer and Client projects, change the Action to “Start”. Also, use the arrows
to the right of the project list so the WsServer project is started first, as shown in
Figure 13-6 . Click the ok button to save these options.
Search WWH ::

Custom Search