Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Almost every line has a comment explaining what it does, so the code should speak for itself. This code will generate the following JavaScript:

Code Block
languagejs
<script type="text/JavaScript">

...


function handleMsg(eventType, msg) { 

...

if(eventType == DDSocketApp.MessageEvent) { 

...


  $('#LOC__Received').val( $('#LOC__Received').val() + msg.data + '\r\n');}

...


}

...


var ws = new DDSocketApp.SocketBase('ws://127.0.0.1:89/WSDemoPage', handleMsg );

...


if(!ws.supported()) {

...


 alert('Sockets are not supported.')

...


}

...


else {

...


  ws.connect();

...


}

And that completes the app. It should look like this:

As soon as you open this url in a second browser, this browser window will be immediately notified that a new client has connected. All messages that you send from either window, will appear in both windows. And there you have it, a very simple websocket application!

...