Tôi đang cố gắng truyền dữ liệu đến trình duyệt. Tôi đang đấu tranh, tuy nhiên, để kết nối nó với trình duyệt. Dưới đây là html của tôi:NHẬN http: // localhost: 3000/socket.io/socket.io.js 404 (Không tìm thấy)
<ul class="tweets"></ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect();
jQuery(function ($) {
var tweetList = $('ul.tweets');
socket.on('tweet', function (data) {
tweetList .prepend('<li>' + data.user + ': ' + data.text + '</li>');
});
});
</script>
Và đây là những phần liên quan của app.js tôi:
var express = require('express')
, twitter = require('ntwitter')
, http = require('http')
, path = require('path');
var app = express();
var io = require('socket.io').listen(app);
app.get('/', function (req, res) { res.sendfile(__dirname + '/index.html'); });
app.listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
io.sockets.volatile.emit('tweets', {
user: data.user.screen_name,
text: data.text,
geo : geo,
latitude: latitude,
longitude: longitude
});
Tôi đã cài đặt socket.io 0.9.16 qua tập tin packages.json tôi:
"dependencies": {
"express": "3.2.6",
"jade": "*",
"ntwitter":"0.2.10",
"socket.io":"0.9.x"
}
Có ai giúp tôi ở đây không? Tại sao nó không thể tìm thấy tập tin?
Đào sâu hơn một chút. Để kiểm tra ổ cắm, tôi đặt này trong app.js:
var socket = io.listen(app);
Và tôi nhận được lỗi:
TypeError: Object #<Manager> has no method 'listen'
at Object.<anonymous> (/home/andy/dev/node/mytwittermap/app.js:49:17)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
lớn - mà bây giờ dường như được làm việc (nhiều thông tin gỡ lỗi tốt trong giao diện điều khiển). Bây giờ, tại sao nó không hiển thị trong trình duyệt. cảm ơn rất nhiều về sự giúp đỡ của bạn. – babbaggeii
tôi yêu bạn ..... –