English 中文(简体)
Socket.io + PhoneGap + 电话
原标题:Socket.io + PhoneGap

当我尝试使用""https://socket.io/" rel="不跟随 noreferrer" >Socket.IO PhoneGap 我理解这个错误:

(在iOS上,插座.io应该支持)

Access-Control-Allow-Origin不允许原产无效。

这是因为我的应用程序是通过field:// 协议提供的。 我能做些什么来绕过它?

谢谢!

问题回答

您必须在 PhoneGap. plist 中的“ 外部住家” 密钥中添加套接字主机 。

"http://wiki.phonegap.com/w/page/41631150/PhoneGap%20for%20iOS%20FAQ" rel=“noreferrer” >Faq :

Q。 与外部主机的链接和从外部主机导入的文件不装入吗?

A. The latest code has the new white-list feature. If you are referencing external hosts, you will have to add the host in PhoneGap.plist under the "ExternalHosts" key. Wildcards are ok. So if you are connecting to "http://phonegap.com", you have to add "phonegap.com" to the list (or use the wildcard "*.phonegap.com" which will match subdomains as well). (Note: If you open the plist file in Xcode, you won t need to fiddle with the XML syntax.)

您必须编辑 colonova. xml 并添加对 Socketio 主机的访问权限 :

<access origin="HOST*"/> 

索引.html(用套接字示例):

...
<script src="HOST/socket.io/socket.io.js"></script>
<script>
    var socket = io.connect( HOST );
    socket.on( news , function (data) {
        socket.emit( my other event , { my:  data  });
    });
</script>
...

app.js (服务器侧射手/基本套接字示例) :

var io = require( socket.io ).listen(80);

io.sockets.on( connection , function (socket) {

socket.emit( news , { hello:  world  });
    socket.on( my other event , function (data) {
        console.log(data);
    });
});

您必须替换的 HOST 代之以您的 socket. io 服务器的主机名!

该网站使用PeetGap 协议file://file:// 打开。

file:// file:// 协议没有设定 WebSocket 连接的源代码, 因此浏览器会提出安全例外, 如果服务器不设置 Access- control- Allow- Origin 信头以响应 COS

考虑使用一些 PhoneGap 插件, 例如以下插件, 它使用本地代码来处理连接, 但可以在 Webview 中启用一个 WebSocket API( 希望符合标准 )

Android:https://github.com/anismilles/websocket-android-phonegap>/a>

iPhone:https://github.com/remy/PhoneGap-Plugin-WebSocket' rel=“noreferrer'>https://github.com/remy/PhoneGap-Plugin-WebSocket

这些插件是我发现的第一个插件, 不知道它们有多少是积极开发和稳定的

所以如果以文件:// url 协议在PhoneGap中打开的网页是发送头条“ Access- control- Allow- Origin: * ” - 理论上它应该全部与 socket.io 一起工作?

(这有可能通过《南锡尔议定书》这样做, 但我不想在不知道修补方法的情况下 进入这个兔子洞)





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.