Advertisement
dathor

XSockets.NET JsSample001

Feb 27th, 2012
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var ws = {};
  2.         $(function () {
  3.             "use strict";
  4.             // Make a connection to the WebSocket
  5.             ws = new jXSockets.xWebSocket("ws://dev.xsockets.local:4502/GenericText", "");
  6.             // Listen to the "onmessage" event of out WebSocket
  7.             ws.bind("open", function (msg) {
  8.                 $("button").bind("click", function () {
  9.                     var msg = {
  10.                         Text: $("input").val()
  11.                     };
  12.                     // Publish the message 'msg' to the subscriber named 'one'
  13.                     ws.trigger("one", msg);
  14.                 });
  15.             });
  16.             // Subscribe to the messages named 'one'
  17.             ws.bind("one", function (msg) {
  18.                 $("<p>").text(msg.Text).appendTo("#one");
  19.             });
  20.             // Subscribe to the messages named 'two'
  21.             ws.bind("two", function (msg) {
  22.                 $("<p>").text(msg.Text).appendTo("#two");
  23.             });
  24.             // Subscribe to the messages named 'three'
  25.             ws.bind("three", function (msg) {
  26.                 $("<p>").text(msg.Text).appendTo("#three");
  27.             });
  28.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement