nodejs socket.io:failed:在Apache2 Server上进行WebSocket握手时出错

时间:2018-06-15 05:25:25

标签: node.js websocket socket.io apache2

当我开始访问网站上的nodejs应用程序" zeyeland.com/bomberkidsonline"我收到此错误:

WebSocket connection to 'wss://www.zeyeland.com/socket.io/? 
EIO=3&transport=websocket&sid=8VoMFQEbl8GyoBxHAAAC' failed: Error 
during WebSocket handshake: Unexpected response code: 400. 

这很奇怪,因为网络套接字游戏在某种程度上有效。 这是我的apache配置文件的样子,我的reverseProxy for web socket不正确吗?

    ProxyPass        /socket.io http://localhost:3000/socket.io
    ProxyPassReverse /socket.io http://localhost:3000/socket.io

    <Proxy *>
            Order deny,allow
            Allow from all 
    </Proxy>
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass /bomberkidsonline http://localhost:3000/
    ProxyPassReverse bomberkidsonline/ http://localhost:3000/

以下是我的index.html文件中使用的脚本标记

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js"></script>

运行app的主文件:index.js文件,使用sendFile加载正确的index.html(导致zeyeland.com/bomberkidsonline)

const app = express();

const server = require('http').Server(app);
const io = require('socket.io')(server); // Pass server to it instead 
of port

// my fancy logic
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});

//此代码正在缩短并显示文件结构    socket.on(&#39; newPlayer&#39;,function(playerId){    console.log(&#34;用户连接:&#34; + playerId); .....等

server.listen(3000, function(){
console.log('listening on *:3000');
});

当我开始运行我的nodejs应用程序并访问zeyeland.com/bomberkidsonline时,服务器会回复说用户已连接并断开连接。这让我知道我的插座在某种程度上工作但不完全。该游戏似乎有效,但如果你控制日志,你会看到下面提到的错误。

WebSocket connection to 'wss://www.zeyeland.com/socket.io/? 
EIO=3&transport=websocket&sid=8VoMFQEbl8GyoBxHAAAC' failed: Error 
during WebSocket handshake: Unexpected response code: 400. 

0 个答案:

没有答案