客戶端錯誤是:socket.io客戶端的NodeJS節目 「GET HTTP://本地主機:8888/socket.io/1/T = 1342788870007 404(未找到)」
GET http://localhost:8888/socket.io/1/?t=1342788870007 404 (Not Found)socket.io.js:1632
Socket.handshake socket.io.js:1632
Socket.connect socket.io.js:1671
Socket socket.io.js:1530
io.connect socket.io.js:91
(匿名功能)
我的客戶JS:
var socket = new io.connect("http://localhost", 8888);
socket.on("chatRoom", function(data){
$("#log").html($("#log").html() + "<br>" + data);
})
$("#chatform").submit(function (event) {
event.preventDefault();
socket.emit('chatRoom', $("#chat").val())
})
,我的服務器是:
var express = require('../node_modules/express'),
app = express.createServer(),
io = require('../node_modules/socket.io').listen(app),
fs = require('fs');
app.use(express.bodyParser());
var port = 8888;
// get html page ok
app.get('/html/*', function (req, res) {
res.sendfile(__dirname + '/html/' + req.params[0]);
});
// chat
io.sockets.on('connection', function (socket) {
socket.on("login", function(message){
socket.emit('chatRoom', "sombody connect");
})
socket.on("chatRoom", function(data){
socket.emit('chatRoom',"from server");
})
})
app.listen(port);
誰能告訴我什麼是錯的? 我的用戶表示在+服務器socket.io,我用socket.io.js在客戶端 服務器和客戶端在本地主機
'io.connect()'不打算用'new'調用。 – ebohlman 2012-07-20 23:15:51