我正在尝试使用websockets连接Primus:
WebSocket connection to 'wss://dev.dylaan.nl/primus/?_primuscb=1417355606238-6' failed: WebSocket opening handshake was canceled
我的NodeJS脚本:
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" });客户端:
var primus = new Primus("wss://dev.dylaan.nl")我刚开始接触这类东西,但我不知道现在出了什么问题,我已经阅读了Primus的文档,我也尝试过谷歌搜索,但我可以找到答案。
当我将协议改为ws而不是wss时,我得到以下错误
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
嗯,我的VPS位于ngnix反向代理之后。我无法访问that.So,这就是我使用wss的原因。
演示:http://dev.dylaan.nl/play
有人能帮帮忙吗?
谢谢!
发布于 2014-12-15 16:24:05
在我看来,您的nginx服务器配置不正确,它阻塞了WebSocket连接,导致返回400错误。有关如何配置服务器以允许websocket连接的信息,请参阅http://nginx.com/blog/websocket-nginx/。
如果您无法让主机/vps验证是否允许WebSocket连接,您可以通过在客户端代码中提供选项{ websocket: false },在Primus中完全关闭WebSockets:
new Primus("http://dev.dylaan.nl", { websocket: false })我还注意到你使用的是wss/ws,而不是Primus要求的http,我们会自动将基于HTTP的url重写为正确的格式。
https://stackoverflow.com/questions/27214090
复制相似问题