GET http://localhost:3000/socket.io/socket.io.js 404(未找到) [英] GET http://localhost:3000/socket.io/socket.io.js 404 (Not Found)

查看:140
本文介绍了GET http://localhost:3000/socket.io/socket.io.js 404(未找到)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将数据流式传输到浏览器.但是,我正在努力将其连接到浏览器.这是我的 html:

I'm trying to stream data to the browser. I'm struggling, however, to connect it to the browser. Here's my html:

<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>

这是我的 app.js 的相关部分:

And here's the relevant parts of my app.js:

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
                });

我通过我的packages.json文件安装了socket.io 0.9.16:

I installed socket.io 0.9.16 via my packages.json file:

"dependencies": {
    "express": "3.2.6",
    "jade": "*",
    "ntwitter":"0.2.10",
    "socket.io":"0.9.x"
  }

有人可以帮我吗?为什么找不到文件?

Can anyone help me out here? Why can't it find the file?

再深入一点.为了测试套接字,我把它放在 app.js 中:

Digging a bit deeper. To test the socket, I put this in the app.js:

var socket = io.listen(app);

我得到了错误:

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

推荐答案

你可以试试这个:

var http = require('http');
var app = express();
var server = http.createServer(app);

var io = require('socket.io').listen(server);

我想,您必须实例化 socket.io 服务器.

I guess, you will have to instantiate the socket.io server.

这篇关于GET http://localhost:3000/socket.io/socket.io.js 404(未找到)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆