从客户端连接到基于sails的服务器 [英] Connect from a client to a sails based server

查看:174
本文介绍了从客户端连接到基于sails的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用sails.io库连接到我的cordova客户端的基于sails的服务器。
这是我的客户代码:

I am trying to connect to my sails based server from my cordova client using the library sails.io. this is my client code:

<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>
<script src="lib/angular-socket-io/socket.js"></script>
<script src="lib/angular-sails/src/ngSails.js"></script>
<script src="lib\socket.io-client\socket.io.js"></script>
<script src="lib/sails.io.js/sails.io.js"></script>
<script type="text/javascript">
    io.sails.useCORSRouteToGetCookie = false;
    io.sails.url = 'http://178.62.83.248:1337/';
</script>

当我打开浏览器,我得到这个错误:

when i open the browser i get this error:

        Socket is trying to reconnect to Sails...
_-|>_-  (attempt #1)


  sails.io.js:136  
    Socket is trying to reconnect to Sails...
_-|>_-  (attempt #2)

,它会继续尝试重新连接(它不会停止)。
i已经在我的服务器上使用socket.io建立了聊天,但是这是在本地,所以我很确定它与cors有关系。

and it keep trying to reconnect(it doesn't stop). i have already build a chat on my server using socket.io but that was locally so i'm pretty sure its has something to do with cors.

推荐答案

您的问题可能是您的Sails版本与您的sails.io.js版本不匹配。当您使用 sails生成Sails v0.10.5应用程序生成新时,它会为您提供适当版本的sails.io.js。但是如果你只是 npm install sails.io.js ,你会得到一个出色的版本,这是为即将到来的v0.11版本的Sails工作,使用Socket.io 1.0。

Your problem is likely a mismatch between your version of Sails and your version of sails.io.js. When you generate a Sails v0.10.5 app with sails generate new, it gives you the appropriate version of sails.io.js. But if you just npm install sails.io.js, you'll get the bleeding-edge version which is designed to work with the imminent v0.11 release of Sails, using Socket.io 1.0.

最简单的做法是下载Sails使用的档案,您可以取得此处

Easiest thing to do here would be just download the file that Sails would use, which you can get here.

这篇关于从客户端连接到基于sails的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆