I'm trying to connect with Primus using websockets:
WebSocket connection to 'wss://dev.dylaan.nl/primus/?_primuscb=1417355606238-6' failed: WebSocket opening handshake was canceled
My NodeJS script:
var express = require("express")
, fs = require("fs")
, path = require("path")
, moment = require("moment")
, Primus = require("primus")
, compression = require("compression")
, app = express()
, http = require("http").createServer(app)
, jsp = require("uglify-js").parser
, pro = require("uglify-js").uglify
, primus = new Primus(http, { transformer: "websockets" });
Client:
var primus = new Primus("wss://dev.dylaan.nl")
I'm new to this kind of stuff, but I don't know whats wrong now, I have read the docs from Primus, I have also tried to Google but I can find the answer.
When I change to protocol to ws
instead of wss
I get the error
Error during WebSocket handshake: Unexpected response code: 426
http 426 may mean that you are trying to connect with an unsupported websocket protocol version
Also, if you are connecting through a proxy, the proxy may remove the "upgrade" header from the request since it is marked as "connection" header. Switch to WSS:// to prevent that.
@ Unexpected response code: 426 with PhanthomJS Websocket client/ROSLIB
Well, my VPS is behind a ngnix reversed proxy. I have no access to that.So thats why I'm using wss.
Demo: http://dev.dylaan.nl/play
Can somebody help?
Thanks!
It seems to me that you've configured your nginx server incorrectly and that it's blocking WebSocket connections causing a 400 error to be returned. See http://nginx.com/blog/websocket-nginx/ on how you can configure the server to allow websocket connections.
If you cannot get your host/vps to verify that WebSocket connects are allowed you can turn off WebSockets completely in Primus by supplying the option
{ websocket: false }
in the client code:I also noticed you used
wss/ws
instead ofhttp
which Primus requires, we will rewrite the HTTP based url in to the correct format automatically.