title: Websocket web client gets 1006 when connecting with wss
body: <p>I have a websocket node.js server and successfully connected from ios, android. But, failed when connecting using rxjs/webSocket in angular web app, got 1006 back.</p>
  <p>I then run websocket server locally, connect localhost:4200 angular web app with the server-&gt; ws://localhost:3000/ws, it works fine. Why can not connect with wss one.</p>
  <p>Server:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const app = express();
  const server = createServer(app);
  const cors = require('cors');
  
  app.use("/", express.static("public"));
  var corsOptions = {
    origin: 'http://localhost:4200',
    credentials: true
  };
  app.use(cors(corsOptions));
  
  const wsApp = expressWs(app, server).app;
  wsApp.ws("/ws", handleSocketConnection);
  
  const port = process.env.PORT || 3000;
  server.listen(port, () =&gt; {
    console.log(`server started on http://localhost:${port}`);
  });</code></pre>
  </div>
  </div>
  </p>
  <p>Client:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public initSocket(clientId): void {
      console.log('init socket');
      this.socket = webSocket(environment.webSocket);
  
      this.socket.next({ "channel": "login", "name": clientId });
  
  }
  
  public getMessage(): Observable&lt;IWebsocketMessage&gt; {
      return new Observable&lt;IWebsocketMessage&gt;(observer =&gt; {
          this.socket.subscribe((data: IWebsocketMessage) =&gt; {
              console.log('message received: ' + JSON.stringify(data));
              observer.next(data);
          }, error =&gt; {
              console.log(error);
          });
  
  
      });
      //    return this.socket.asObservable();
  }</code></pre>
  </div>
  </div>
  </p>