title: Can't open websocket on mobile devices
body: <p>I am attempting to set up a websocket with server running on my raspberry pi. The following code is slightly modified from an example I found <a href="https://lowpowerlab.com/2013/01/17/raspberrypi-websockets-with-python-tornado/" rel="nofollow noreferrer">here</a>.</p>
  
  <p>I have built a whole webpage around this example allowing me to control gpio and send messages to a serial device plugged into the pi. Both that site and this example work perfectly from my laptop (windows 10 using Chrome or Firefox).</p>
  
  <p>However when I connect from my phone (Android 5.0.1 using Chrome for android). It appears to never open the socket. In the example code it just displays "messages go here.</p>
  
  <p>My first thought was the chrome on android didn't support websockets but I was able to connect and echo messages on this site <a href="http://www.websocket.org/echo.html" rel="nofollow noreferrer">http://www.websocket.org/echo.html</a>. So it appears the functionality is there.</p>
  
  <p>What else would prevent the socket from opening ?</p>
  
  <p>pysocket.py</p>
  
  <pre><code>import tornado.httpserver
  import tornado.websocket
  import tornado.ioloop
  import tornado.web
  
  class WSHandler(tornado.websocket.WebSocketHandler):
  
    def check_origin(self, origin):
      return True
  
    def open(self):
      print 'New connection was opened'
      self.write_message("Welcome to my websocket!")
  
    def on_message(self, message):
      print 'Incoming message:', message
      self.write_message("You said: " + message)
  
    def on_close(self):
      print 'Connection was closed...'
  
  application = tornado.web.Application([
    (r'/ws', WSHandler),
  ])
  
  if __name__ == "__main__":
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
  </code></pre>
  
  <p>pysocket.php</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;WebSockets with Python &amp; Tornado&lt;/title&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;style type="text/css"&gt;
        body {
          text-align: center;
          min-width: 500px;
        }
      &lt;/style&gt;
      &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
        $(function(){
          var ws;
          var logger = function(msg){
            var now = new Date();
            var sec = now.getSeconds();
            var min = now.getMinutes();
            var hr = now.getHours();
            $("#log").html($("#log").html() + "&lt;br/&gt;" + hr + ":" + min + ":" + sec + " ___ " +  msg);
            //$("#log").animate({ scrollTop: $('#log')[0].scrollHeight}, 100);
            $('#log').scrollTop($('#log')[0].scrollHeight);
          }
  
          var sender = function() {
            var msg = $("#msg").val();
            if (msg.length &gt; 0)
              ws.send(msg);
            $("#msg").val(msg);
          }
  
          ws = new WebSocket("ws://raspberrypi-mike:8888/ws");
          ws.onmessage = function(evt) {
  
            logger(evt.data);
          };
          ws.onclose = function(evt) { 
            $("#log").text("Connection was closed..."); 
            $("#thebutton #msg").prop('disabled', true);
          };
          ws.onopen = function(evt) { $("#log").text("Opening socket..."); };
  
          $("#msg").keypress(function(event) {
            if (event.which == 13) {
               sender();
             }
          });
  
          $("#thebutton").click(function(){
            sender();
          });
        });
      &lt;/script&gt;
    &lt;/head&gt;
  
    &lt;body&gt;
      &lt;h1&gt;WebSockets with Python &amp; Tornado&lt;/h1&gt;
      &lt;div id="log" style="overflow:scroll;width:500px; height:200px;background-color:#ffeeaa; margin:auto; text-align:left"&gt;Messages go here&lt;/div&gt;
  
      &lt;div style="margin:10px"&gt;
        &lt;input type="text" id="msg" style="background:#fff;width:200px"/&gt;
        &lt;input type="button" id="thebutton" value="Send" /&gt;
      &lt;/div&gt;
  
      &lt;a href="http://lowpowerlab.com/blog/2013/01/17/raspberrypi-websockets-with-python-tornado/"&gt;www.LowPowerLab.com&lt;/a&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>