title: PHP Ratchet websocket handshake failing
body: <p>Just started using ratchet. When I firstly tested it, it worked fine with websockets, got requests etc. But now I am doing the same as I did, but the request (onOpen) isn't even getting requested, and I am getting this JS error:</p>
  
  <pre><code>WebSocket connection to 'ws://localhost:8080/' failed: Error during WebSocket handshake: Unexpected response code: 404 
  </code></pre>
  
  <p>jscode:</p>
  
  <pre><code>var conn = new WebSocket("ws://localhost:8080");
  conn.onopen = function(e) {
      console.log("Connected!");
      conn.send("hello server");
  };
  conn.onmessage = function (e) {
      console.log(e.data);
  };
  </code></pre>
  
  <p>And my source code:</p>
  
  <p>Main file:</p>
  
  <pre><code>require __DIR__ . "../../library/loader.php";
  require __DIR__ . "../../vendor/autoload.php";
  
  error_reporting(E_ALL);
  
  use Ratchet\WebSocket\WsServer,
      Ratchet\Http\HttpServer,
      Ratchet\Server\IoServer;
  
  use bin\library\AsynChatServer;
  
  $server = IoServer::factory(
      new HttpServer(
          new WsServer(
              new AsynChatServer()
          )), 8080);
  
  $server-&gt;run();
  </code></pre>
  
  <p>And the server class:</p>
  
  <pre><code>namespace bin\library;
  
  use Ratchet\MessageComponentInterface,
      Ratchet\ConnectionInterface,
      Ratchet\Server\IoConnection;
  
  use bin\library\database\Db;
  
  use bin\library\model\Client,
      bin\library\model\PacketManager;
  
  class AsynChatServer implements MessageComponentInterface {
  
      private $clients;
  
      /** @var Db */
      private $database;
  
      /** @var PacketManager */
  
      private $packets;
  
      function __construct()
      {
          $this-&gt;clients = array();
          $this-&gt;database = new Db();
          $this-&gt;packets = new PacketManager($this);
  
          AsynChatServer::println("Server has started up.");
      }
  
      /**
       * When a new connection is opened it will be passed to this method
       * @param  ConnectionInterface $conn The socket/connection that just connected to your application
       * @throws \Exception
       */
  
      function onOpen(ConnectionInterface $conn)
      {
          echo "request";
          /** @var $client Client */
          $client = new Client($conn);
          $this-&gt;clients[$conn-&gt;resourceId] = $client;
          AsynChatServer::println("New client accepted: " + $client-&gt;getClient()-&gt;getRemoteAddress());
      }
  
      /**
       * This is called before or after a socket is closed (depends on how it's closed).  SendMessage to $conn will not result in an error if it has already been closed.
       * @param  ConnectionInterface $conn The socket/connection that is closing/closed
       * @throws \Exception
       */
      function onClose(ConnectionInterface $conn)
      {
          // TODO: Implement onClose() method.
      }
  
      /**
       * If there is an error with one of the sockets, or somewhere in the application where an Exception is thrown,
       * the Exception is sent back down the stack, handled by the Server and bubbled back up the application through this method
       * @param  ConnectionInterface $conn
       * @param  \Exception $e
       * @throws \Exception
       */
      function onError(ConnectionInterface $conn, \Exception $e)
      {
          // TODO: Implement onError() method.
      }
  
      /**
       * Triggered when a client sends data through the socket
       * @param  \Ratchet\ConnectionInterface $from The socket/connection that sent the message to your application
       * @param  string $msg  The message received
       * @throws \Exception
       */
  
      function onMessage(ConnectionInterface $from, $msg)
      {
          /** @var $client Client */
          $client = $this-&gt;clients[$from-&gt;resourceId];
          AsynChatServer::println("Paccket received from: " . $client-&gt;getClient()-&gt;getRemoteAddress());
          $this-&gt;packets-&gt;processPacket($client, $msg);
      }
  
      public static function println($message) {
          echo $message . "\n";
      }
  
      public function getDB() {
          return $this-&gt;database;
      }
  
  }
  </code></pre>
  
  <p>Is there something wrong? Could the library be corrupted so I need to re-set it up?
  This is the output i get when I run:</p>
  
  <pre><code>c:\xampp1\php&gt;php c:/xampp1/htdocs/AsynChat/bin/AsynChat.php
  Server has started up.
  </code></pre>
  
  <p>Nothing else when I connect, no signle error.</p>
  
  <p>What is wrong?</p>
  
  <p>NETSTAT -A:</p>
  
  <pre><code>  TCP    127.0.0.1:8080         Ben-╧╩:0               LISTENING
    TCP    127.0.0.1:8080         Ben-╧╩:0               LISTENING
  </code></pre>
  
  <p>My App.php constructor:</p>
  
  <pre><code>public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null) {
  </code></pre>