简体   繁体   English

在 html 标签中使用 socket.io 时出错

[英]Getting error while using socket.io in html tag

I am learning socket.io from their documentation but I can not solve this error, which I guess appearing due to using the script tag before body end.我正在从他们的文档中学习 socket.io 但我无法解决此错误,我猜这是由于在正文结束之前使用脚本标记而出现的。

This is the image showing the tag I am getting error and here you can also understand my directory structure:这是显示我收到错误的标签的图像,在这里您还可以了解我的目录结构:图片

Thanks in advance, I have tried all earlier solutions I have found on StackOverflow在此先感谢,我已经尝试了在 StackOverflow 上找到的所有早期解决方案

The solution is that you need to copy socket.io.js to a public folder (something as resources/js/socket.io.js).解决方案是您需要将socket.io.js复制到公共文件夹(资源/js/socket.io.js)。 This is not the preferred way.这不是首选方式。

Instead, if your Socket.io server listens properly to your HTTP server, it will automatically serve the client file via http://localhost:<port>/socket.io/socket.io.js , now you don't need to find socket client js file or copy in a public folder as resources/js/socket.io.js & serve it manually.相反,如果您的 Socket.io 服务器正确侦听您的 HTTP 服务器,它将自动通过http://localhost:<port>/socket.io/socket.io.js提供客户端文件。客户端 js 文件或作为resources/js/socket.io.js复制到公共文件夹中并手动提供。

If still facing an issue then use the following CDN link Read here for more info如果仍然遇到问题,请使用以下 CDN 链接阅读此处了解更多信息

<script src="https://cdn.socket.io/3.1.1/socket.io.min.js" integrity="sha384-gDaozqUvc4HTgo8iZjwth73C6dDDeOJsAgpxBcMpZYztUfjHXpzrpdrHRdVp8ySO" crossorigin="anonymous"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM