Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取错误套接字正在尝试重新连接到Sails_Javascript_Node.js_Socket.io_Sails.js - Fatal编程技术网

Javascript 获取错误套接字正在尝试重新连接到Sails

Javascript 获取错误套接字正在尝试重新连接到Sails,javascript,node.js,socket.io,sails.js,Javascript,Node.js,Socket.io,Sails.js,我的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 g

我的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()`)
});
当我查看其他一些帖子时,有人说与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>
在此服务器上找不到请求的URL/socket.io/

本地主机端口80上的Apache/2.2.22(Ubuntu)服务器
有什么问题吗?

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

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

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

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

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

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

404来自试图连接到服务器的客户端套接字,该服务器不接受套接字连接

如果应用程序中未使用套接字,则需要删除sails.io.js脚本


下面两个选项对我来说都不起作用,但这都起作用了。我删除了sails.io.js文件

404来自试图连接到服务器的客户端套接字,该服务器不接受套接字连接

如果应用程序中未使用套接字,则需要删除sails.io.js脚本


下面两个选项对我来说都不起作用,但这都起作用了。我删除了sails.io.js文件

酷…意识到从Sails加载
.js
文件时,我没有给您提供正确的路径(因为它将
资产
文件夹作为公共文件的根公开)。现在修复了,所以两个选项都可以使用。是的,关于公开实际的项目路径是正确的。我按照你的建议改了路。io.sails.url=“”;似乎两行都需要。谢谢你的帮助@sgress454我知道我应该为此创建一个新问题,但没有找到任何解决方案。我使用nginx作为代理服务器,因此当请求/node/anything时,它会被重定向到localhost:3000,前端应用程序会使用
script type=“text/javascript”src=“/node/js/dependencies/sails.io.js”>
io.sails.url='/node',引用sails API应用程序中的socket.io.js;导致同样的错误。任何helpCool…都意识到,从Sails加载
.js
文件时,我没有为您提供正确的路径(因为它将
资产
文件夹作为公共文件的根公开)。现在修复了,所以两个选项都可以使用。是的,关于公开实际的项目路径是正确的。我按照你的建议改了路。io.sails.url=“”;似乎两行都需要。谢谢你的帮助@sgress454我知道我应该为此创建一个新问题,但没有找到任何解决方案。我使用nginx作为代理服务器,因此当请求/node/anything时,它会被重定向到localhost:3000,前端应用程序会使用
script type=“text/javascript”src=“/node/js/dependencies/sails.io.js”>
io.sails.url='/node',引用sails API应用程序中的socket.io.js;导致同样的错误。有什么帮助吗
<script src="http://localhost:1337/js/dependencies/sails.io.js">
io.sails.url = "http://localhost:1337";