【发布时间】:2013-07-27 01:51:59
【问题描述】:
这是测试用例...
app.js
var express = require('express'),
http = require('http'),
//other variables
var app = express();
var server = http.createServer(app);
var io = require("socket.io").listen(server)
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
});
html_index.js
$(document).ready(function()
{
var socket = io.connect();
socket.on('news', function (data) {
console.log(data);
});
});
我收到这个错误
WebSocket connection to 'ws://localhost:26000/socket.io/1/websocket/%3Ch2%3Efile%20not%20found!%20error%20404!%3C/h2%3E' failed: WebSocket is closed before the connection is established. socket.io.js:2438
WS.close socket.io.js:2438
Socket.onDisconnect socket.io.js:1967
Transport.onDisconnect socket.io.js:1362
Transport.onClose socket.io.js:1456
(anonymous function)
我正在使用
express 3
socket.io 0.9
nodejs 0.10
【问题讨论】:
-
为我工作.. 您在哪里看到这些错误?端口 26000 是什么?默认快递端口不是3000吗?
-
我使用 26000,对我不起作用,我找不到问题,我在客户端看到这个错误,使用 chrome
-
套接字正在尝试请求(未编码)
/socket.io/1/websocket/<h2>file not found! error 404!</h2>。检查npm ls是否有任何缺失的依赖项。或者尝试删除并重新安装socket.io。注意:socket.io的依赖包括native addon、ws,需要安装node-gyp和its external dependencies。 -
26000 在 chrome 上也适用于我。我真的很想帮忙,但我无法传播错误。
-
检查了所有依赖项,我发现了这个...当我将服务器上的 io 端口更改为 26001 和 io.connect('localhost:26001');在客户端它可以工作
标签: javascript node.js express socket.io