简体   繁体   English

Websocket 和跨域

[英]Websocket and cross-domain

Currently, I am developing two webapps :目前,我正在开发两个 webapps :

  • the core, developed in Java with Vert.x, receives data from a lot of other apps and sends it to client)核心,使用 Vert.x 用 Ja​​va 开发,从许多其他应用程序接收数据并将其发送到客户端)
  • the client, developed in PHP/JS, display data from the core.用 PHP/JS 开发的客户端显示核心数据。

The client isn't on the same domain as my core for the production phase.在生产阶段,客户端与我的核心不在同一个域中。

Since my development period, the two webapps are hosted in the same computer.在我的开发期间,这两个 webapp 托管在同一台计算机上。 I used "ws:\\\\localhost:9090" to connect my client to my core and I had no problem to transfer data.我使用“ws:\\\\localhost:9090”将我的客户端连接到我的核心,并且传输数据没有问题。

But, today, I try to replace localhost with my IP Address and, it didn't work :s但是,今天,我尝试用我的 IP 地址替换 localhost,但它不起作用:s

I think that it's because the client isn't in the same domain as the core.我认为这是因为客户端与核心不在同一个域中。 But I don't know how I can correct this problem ?但我不知道如何解决这个问题?

Do you have any idea ?你有什么主意吗 ?

Thanks !谢谢 !

Code example (based on my code but not my code ;) ):代码示例(基于我的代码但不是我的代码;)):

Yes, Websocket can do cross-domain, but you will need to have a handshake in order to get this going.是的,Websocket 可以跨域,但你需要握手才能实现这一点。 You might want to take a look at: http://en.wikipedia.org/wiki/WebSockets for an example of a handshake.您可能需要查看: http : //en.wikipedia.org/wiki/WebSockets以获取握手示例。

Also related and maybe duplicate: Web sockets make ajax/CORS obsolete?同样相关并且可能重复: Web sockets make ajax/CORS obsolete?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM