Javascript 找不到socket.io.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8689877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 07:05:23  来源:igfitidea点击:

Can't find socket.io.js

javascriptsocket.io

提问by Esaevian

Possible Duplicate:
socket.io.js not found

可能重复:
找不到 socket.io.js

I am using the most up to date version of Socket.IO and I'm trying the first example on the how to use page, however, I'm getting an error when I try to get to '/socket.io/socket.io.js'

我正在使用最新版本的 Socket.IO 并且我正在尝试有关如何使用页面的第一个示例,但是,当我尝试访问 '/socket.io/socket. io.js'

The javascript console saying the file doesn't exist. When I check my browser (both http://socket.io/socket.io.jsand https://socket.io/socket.io.js), it isn't up there either. Is the documentation out of date? Where is the socket.io.js file that I'm supposed to include?

javascript 控制台说该文件不存在。当我检查我的浏览器(http://socket.io/socket.io.jshttps://socket.io/socket.io.js)时,它也不在那里。文档是否过时?我应该包含的 socket.io.js 文件在哪里?

I am running this on a Mac with NodeJS running my app.js server.

我在 Mac 上运行它,NodeJS 运行我的 app.js 服务器。

I've tried using "http://cdn.socket.io/stable/socket.io.js" but it seems that is an old version (0.6) and the Javascript console says it doesn't have the "connect" function. (which is weird, I would think that connect is a rather integral function to have in such a library, but I guess not)

我试过使用“ http://cdn.socket.io/stable/socket.io.js”但它似乎是一个旧版本(0.6)并且Javascript控制台说它没有“连接”功能. (这很奇怪,我认为 connect 是这样一个库中一个相当完整的功能,但我想不是)

回答by Michelle Tilley

Your Socket.IO server will handle serving the correct version of the Socket.IO client library; you should not be using one from elsewhere on the Internet. From the top example on the Socket.IO website:

您的 Socket.IO 服务器将处理提供正确版本的 Socket.IO 客户端库;你不应该使用互联网上其他地方的。来自Socket.IO 网站上的顶部示例:

<script src="/socket.io/socket.io.js"></script>

This works because you wrap your HTTP server in Socket.IO (see the example at How To Use) and it intercepts requests for /socket.io/socket.io.jsand sends the appropriate response automatically.

这是有效的,因为您将 HTTP 服务器包装在 Socket.IO 中(请参阅如何使用中的示例),它会自动拦截请求/socket.io/socket.io.js并发送适当的响应。

回答by benesch

I know this seems obvious, but did you install Socket.IO on your server? Then you'll get a local copy of the file at '/socket.io/socket.io.js'.

我知道这看起来很明显,但是您是否在服务器上安装了 Socket.IO?然后,您将在“/socket.io/socket.io.js”处获得文件的本地副本。

npm install socket.io