6 Replies Latest reply on Aug 17, 2012 7:20 AM by Peter Arcuri

    WebSockets support



      I am using RhoMobile Studio 2. On trying to open a websocket connection thus


          var socket = new WebSocket('ws://echo.websocket.org');


          socket.onopen = function () {




          socket.onerror = function (e) {




          socket.onmessage = function(event) {




      ...I get the following error message in the Web Inspector console:


      Unexpected response code:400


      Any pointers? What is the status of websocket support?


      Kind Regards,


        • Re: WebSockets support
          Peter Arcuri

          Hi Devendra, Websocket support is through the rendering engine within the broswer you are using with you Rho app. You may want to do some research to see what version of your browser supports Websocket. Also there may be a Websocket polyfill for your broswer to support the feature.

          • Re: WebSockets support
            Pietro Francesco Maggi

            Hi Devendra,

            a couple of question:

            1. What is the device you're testing websockets on?

            2. Does your server support websockets? Given that you're opening a websockets on localhost, this can be the problem.




              • Re: WebSockets support

                Hi Pietro,


                Answering your questions:


                1. I am using the rhosimulator. Unfortunately ws://localhost:8080/ is an error artifact in the code. I was able to get WebSocket connection to ws://echo.websocket.org to work outside our work network, so the error was probably due to a caching proxy. We are building an Android web app that we plan to deploy as a native app using rho studio. A similar test on the Motorola Xoom tablet was not very encouraging. This is the error message logged while debugging the Android app:


                08-16 15:30:44.380: I/APP(1227): I 08/16/2012 15:30:44:386 000004cb   RhoWebChromeClient| Uncaught ReferenceError: WebSocket is not defined -- From line 12 of http://localhost:48793/app/Bamm


                Does rho studio use the Android WebView as the browser?



                2. We did try and test on rhosimulator with ws://localhost:8080/, without success. The same JavaScript code works as expected in Chrome (21). Our test server on localhost is a simple node.js script that leverages the ws module. Here's how we get it up and running:


                var WebSocketServer = require('ws').Server;

                var wss = new WebSocketServer({port: 8080});


                wss.on('connection', function(ws) {

                  // new client connection

                  console.log('on connection');


                  ws.on('message', function(message) {

                    console.log('message recvd');

                    ws.send(message); // echo




                Kind Regards,