title: How to use Websockets with Pyramid and socket.io?
body: <p>I'm trying to create a simple WebSocket application using Pyramid and socket.io frameworks.
  Server-side code:</p>
  
  <pre><code>from pyramid.response import Response
  from pyramid_socketio.io import SocketIOContext, socketio_manage
  import gevent
  
  def includeme(config):
      '''
      This method is called on the application startup.
      '''
      config.add_route('socket.io', 'socket.io/*remaining')
  
  class ConnectIOContext(SocketIOContext):
      # self.io is the Socket.IO socket
      # self.request is the request
      def msg_connect(self, msg):
          print "Connect message received", msg
          self.msg("connected", hello="world")
  
  # Socket.IO implementation
  @view_config(route_name="socket.io")
  def socketio_service(request):
      print "Socket.IO request running"
      print request
      retval = socketio_manage(ConnectIOContext(request))
      return Response(retval)
  </code></pre>
  
  <p>Client code:</p>
  
  <pre><code>&lt;script&gt;
      var socket = null;
      $(document).ready(function() {
          socket = new io.Socket(null, null);
          socket.on('connect', function() {
          console.log("Connected");
          socket.send({type: "connect", userid: 123});
      });
      socket.on('message', function(obj) {
          console.log("Message received");
          console.log("Message", JSON.stringify(obj));
          if (obj.type == "some") {
              console.log("do some");
          }
      });
      socket.on('error', function(obj) {
          console.log("Error", JSON.stringify(obj));
      });
      socket.on('disconnect', function() {
          console.log("Disconnected");
      });
  
      console.log("Connecting...");
      socket.connect();
  });
  &lt;/script&gt;  
  </code></pre>
  
  <p>I need this code to use web-sockets for the connection, but it falls back to XHR-polling. 
  How can I fix it? </p>
  
  <p>Thanks in advance, Ivan.</p>