Possible Duplicate:
socket.io: Failed to load resource
A simple express + socket.io hellow world app seems doesnt work, i keep getting
"NetworkError: 404 Not Found - http:// localhost:3002/socket.io/socket.io.js"
Anyone know this issue?
code:
app.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);
});
});
index.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' });
});
Your Socket.IO server is listening on port 3002
, but you connected to:
var socket = io.connect('http://localhost');
which by default uses standard port 80
. Try this:
var socket = io.connect('http://localhost:3002');
Also you will probably have to change localhost
to the IP of your machine.
Side note: If you are running Express Server and Socket.IO server on the same port, then you can simply do:
var socket = io.connect();