可能重复:
socket.io:加载资源失败
一个简单的 express + socket.io hello world 应用程序似乎不起作用,我不断收到
“网络错误:404 未找到 - http://localhost:3002/socket.io/socket.io.js”
有人知道这个问题吗?
代码:
应用程序.js
var express = require('express'),
http = require('http');
var app = express();
var server = http.createServer(app);
var io = require('socket.io').listen(server);
app.configure(function () {
app.use(express.static(__dirname + '/public'));
});
app.listen(3002);
io.sockets.on('connection', function(socket) {
socket.emit('news', {hello: 'world'});
socket.on('my other event', function (data) {
console.log(data);
});
});
索引.html
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my:'data' });
});