XSockets fallback is not working in html page

12 views
Skip to first unread message

priya

unread,
Apr 22, 2015, 3:12:02 AM4/22/15
to xsocke...@googlegroups.com
Hello

I have attached the code below. Its a script for fallback. Its working fine in IE10,9,8 when we use the page as .cshtml
But its not working in fallback. As the page is saved as html.
Please explain how to use the fallback in .html page.
Awaiting for ur reply.




<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>XSockets - Simple PubSub With Fallback</title>
</head>
<body>
    <label>Username</label><br />
    <input type="text" id="username" value="Steve" /><br />
    <label>Message</label><br />
    <input type="text" value="Hello World" id="message" /><button id="send">send</button>
    <hr />
    <div data-bind="foreach:messages">
        <div>
            <span data-bind="text:username"></span>: <span data-bind="text:message"></span>
        </div>
    </div>
    <script src="/Scripts/jquery-1.9.0.js"></script>


    <script src="/Scripts/knockout-3.2.0.js"></script>
    <script type="text/javascript">
        //VM
        var vm = { messages: ko.observableArray([]) };
        ko.applyBindings(vm);

        //Connect to the built in "Generic" controller
        var conn = new XSockets.WebSocket('ws://127.0.0.1:9090', ['chat']);
        var controller = conn.controller('chat');

        //Setup a subscription for the topic "chatmessage"
        controller.subscribe('chatmessage', function (d) {
            vm.messages.unshift(d);
        });

        //When button is clicked, publish a chat-message
        document.querySelector("#send").onclick = function () {
            var u = document.querySelector('#username').value;
            var m = document.querySelector('#message').value;
            controller.publish('chatmessage', { username: u, message: m });
        };
    </script>
</body>
</html>

Ulf Björklund

unread,
Apr 22, 2015, 3:34:45 AM4/22/15
to xsocke...@googlegroups.com
Hi
There is no difference between .cshtml and .html when it comes to communication with XSockets.
Your issue is probably that your webapplication is not started since the server-side will not "start" until you require a server side resource.
The html file does not start the server-side but the cshtml will... So before you access the .html file just make a call to the root of your web...
The server-side needs to be started since the fallback uses a webapi-controller.... 

/uffe
Reply all
Reply to author
Forward
0 new messages