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

查看:42
本文介绍了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.

我能想到的唯一其他可能发生的事情是您可能没有链接到客户端文件中的备用端口.除非你在 express 上运行 socket.io 服务器,它在端口 80 上运行.现在创建一个客户端文件,将 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天全站免登陆