Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ws = {};
- $(function () {
- "use strict";
- // Make a connection to the WebSocket
- ws = new jXSockets.xWebSocket("ws://dev.xsockets.local:4502/GenericText", "");
- // Listen to the "onmessage" event of out WebSocket
- ws.bind("open", function (msg) {
- $("button").bind("click", function () {
- var msg = {
- Text: $("input").val()
- };
- // Publish the message 'msg' to the subscriber named 'one'
- ws.trigger("one", msg);
- });
- });
- // Subscribe to the messages named 'one'
- ws.bind("one", function (msg) {
- $("<p>").text(msg.Text).appendTo("#one");
- });
- // Subscribe to the messages named 'two'
- ws.bind("two", function (msg) {
- $("<p>").text(msg.Text).appendTo("#two");
- });
- // Subscribe to the messages named 'three'
- ws.bind("three", function (msg) {
- $("<p>").text(msg.Text).appendTo("#three");
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement