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>
任何帮助有什么不妥?
答案 0 :(得分:5)
您正在端口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";
答案 1 :(得分:0)
404来自客户端套接字,试图连接到服务器,该服务器不接受套接字连接。
如果您未在应用程序中使用套接字,则需要删除sails.io.js脚本。
以及以下两个选项对我均不起作用,但这可行。我删除了sails.io.js文件。