gpt4 book ai didi

javascript - 出现错误 Socket 正在尝试重新连接到 Sails

转载 作者:太空宇宙 更新时间:2023-11-04 02:57:43 25 4
gpt4 key购买 nike

我的 Sails 版本是 0.11.2,使用端口 1337 运行

在assets/js/dependency/sails.io.js中,我可以看到版本为0.11.0

下面是客户端脚本。

<script src="http://localhost/project/assets/js/dependencies/sails.io.js"></script>
<script type="text/javascript">

// `io` is available as a global.
// `io.socket` will connect automatically, but at this point in the DOM, it is not ready yet
// (think of $(document).ready() from jQuery)
//
// Fortunately, this library provides an abstraction to avoid this issue.
// Requests you make before `io` is ready will be queued and replayed automatically when the socket connects.
// To disable this behavior or configure other things, you can set properties on `io.sails`.
// You have one cycle of the event loop to set `io.sails.autoConnect` to false before the auto-connection
// behavior starts.

io.socket.get('/hello', function serverResponded (body, JWR) {

// JWR ==> "JSON WebSocket Response"
console.log('Sails responded with: ', body);
console.log('with headers: ', JWR.headers);
console.log('and with status code: ', JWR.statusCode);

// first argument `body` === `JWR.body`
// (just for convenience, and to maintain familiar usage, a la `JQuery.get()`)
});

我收到类似的错误

Socket is trying to reconnect to Sails...

当我检查其他一些帖子时,有一些与 sails 版本相关的内容。我尝试将 sails.io.js 版本更改为 0.11.2,但仍然出现同样的错误。

这个错误和端口有关系吗?因为下面请求的响应是404

http://localhost/socket.io/?__sails_io_sdk_version=0.11.2&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=1444654910110-52

回应

<p>The requested URL /socket.io/ was not found on this server.</p>
<address>Apache/2.2.22 (Ubuntu) Server at localhost Port 80</address>

有什么问题可以帮忙吗?

最佳答案

您正在端口 1337 上运行 Sails 应用程序,但从端口 80 加载 sails.io.js 文件(因为您没有指定其他端口):

<script src="http://localhost/project/assets/js/dependencies/sails.io.js">

我猜您有一个在端口 80 上运行的 Apache 服务器,因此它会查找 sails.io.js 文件并返回它,但随后套接字客户端假定它也应该在端口 80 上进行连接。

使用端口更新您的 script 标记:

<script src="http://localhost:1337/js/dependencies/sails.io.js">

或者指定要连接的套接字的备用 URL,在 io.socket.get 之前使用以下代码:

io.sails.url = "http://localhost:1337";

关于javascript - 出现错误 Socket 正在尝试重新连接到 Sails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33086216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com