My Sails版本为0.11.2,运行端口为1337
在assets / js / dependencies / 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>
有什么帮助有什么不对?
2 回答
您正在端口1337上运行Sails应用程序,但是从端口80加载
sails.io.js
文件(因为您没有指定其他端口):我猜你有一个在端口80上运行的Apache服务器,所以它找到
sails.io.js
文件并返回它,但是套接字客户端假设它也应该在端口80上连接 .使用端口更新
script
标记:或者在
io.socket.get
之前使用以下代码指定要连接的套接字的备用URL:404来自尝试连接到服务器的客户端套接字,该服务器不接受套接字连接 .
如果您未在应用程序中使用套接字,则需要 delete the sails.io.js script .
以下两个选项对我不起作用,但这有效 . 我删除了sails.io.js文件 .