Socket.io不在/socket.io/socket.io.js中提供 [英] Socket.io is not served in /socket.io/socket.io.js

查看:217
本文介绍了Socket.io不在/socket.io/socket.io.js中提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里阅读了有关我在node.js中的问题的答案,但是我的问题仍然存在.在服务器中使用socket.io时,一切看起来都不错,但是在客户端,chrome表示: 加载资源失败:服务器响应状态为404(未找到) 本地主机:3382/socket.io/socket.io.js

i've read the answers here about my problem in node.js, but my problem persists. With socket.io in the server, everything looks ok, but in client side, chrome says: Failed to load resource: the server responded with a status of 404 (Not Found) localhost:3382/socket.io/socket.io.js

var express = require("express");
var http = require("http");
var _io = require("socket.io");

var PORT = 3382;

var app = express();

app.listen(PORT, function(){
console.log("Listening from "+PORT);
});

var server = http.createServer(app);
var io = _io.listen(server);

有了玉,我有:

script(src='/js/jquery.js')
script(src='/js/chat.js')
script(src="socket.io/socket.io.js")

我在静态文件夹中有js文件夹,它可以正常工作.我不知道是否是因为版本(节点-v显示v0.8.16),我如何查看express和socket.io的版本?

I have the folder js in a folder static, it works ok. I don't know if it's because the versions (node -v show v0.8.16), how do i see versions of express and socket.io?

推荐答案

通读 http://expressjs.com/api.html#app.listen ,请注意app.listen的定义方式.

Read through http://expressjs.com/api.html#app.listen, note how app.listen is defined.

简而言之:将app.listen替换为server.listen.

这篇关于Socket.io不在/socket.io/socket.io.js中提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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