未找到Node.js socket.io.js或未定义io [英] Node.js socket.io.js not found or io not defined

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

问题描述

我试图在我的freebsd服务器上运行一个node.js应用程序,但我无法使socket.io库使用它。我试过包括:

I'm trying to run a node.js application on my freebsd server, but I can't get the socket.io library to work with it. I've tried including:

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

这给出了404错误,如果我直接链接到该文件(即它在我的位置public_html文件夹)我得到了io未定义的错误。

Which gives a 404 error, and if i link directly to the file (i.e. where it is in my public_html folder) I get the io not defined error.

提前致谢

推荐答案

尝试创建另一个具有此单行的node.js应用程序,然后使用node.js运行它

Try creating another node.js application that has this single line in it and then run it with node.js

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

然后在您的浏览器中访问 http://127.0.0.1:8000 ,你应该得到友好的欢迎来到socket.io。问候。如果你得到这个,那么socket.io正在运行,并且会提供socket.io.js文件。

Then in your browser visit http://127.0.0.1:8000 and you should get the friendly "Welcome to socket.io." greeting. If you are getting this then socket.io is running and will serve the socket.io.js file.

我能想到的唯一的其他事情可能会发生是你可能没有链接到客户端文件中的备用端口。除非你在运行在端口80上的express上运行socket.io服务器。现在,创建一个客户端文件,其中socket.io的脚本源设置为

The only other thing that I can think of that might be happening is that you might not be linking to the alternate port in your client file. Unless you're running the socket.io server on express which is running on port 80. For now create a client file that has the script source for socket.io set to

<script src="http://127.0.0.1:8000/socket.io/socket.io.js"> </script>

这应该连接到在端口8000上运行的socket.io服务器并获取socket.io.js文件。

This should connect to the socket.io server running on port 8000 and get the socket.io.js file.

这篇关于未找到Node.js socket.io.js或未定义io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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