我创建并运行了nodejs
文件server.js
:
var io = require('socket.io').listen(8080);
io.set('log level', 1);
io.sockets.on('connection', function (socket) {
// pass
});
和客户client.js
:
window.onload = function(){
var connected = function(){
console.log("connect")
}
var start = function() {
socket = new io.Socket();
socket.connect('http://localhost:8080');
socket.on('connect', connected);
};
start();
}
我加入了socket.io
:
<script src="http://localhost:8080/socket.io/socket.io.js"></script>
但在调试器中我看: 请求网址:http://undefined/socket.io/1/?t = 1359905123022
我正在使用django,我在8000端口运行django服务器...
WTF?
答案 0 :(得分:1)
尝试在client.js中替换这一行:
socket = new io.Socket();
socket.connect('http://localhost:8080');
为:
var socket = io.connect('http://localhost:8080');