如何配置 cometd 才能与 google chrome 一起正常工作?

发布于 2024-10-07 02:42:30 字数 1144 浏览 9 评论 0原文

我已使用

注意:本周末 -grails/" rel="nofollow">这篇精彩的博客文章作为指南和 cometd grails 插件,我能够将 cometd 与我现有的 grails 应用程序一起安装。在 FireFox 和 IE 中一切正常(不管你信不信),但我在使用 Google Chrome 时遇到了问题。据我所知,它发生在我的 javascript 中的 comet.init() 行上。

使用 Chrome 的开发者工具时,我看到以下错误: WebSocket 的 URL 方案错误 http://localhost:8080/myapp/cometd/handshake

我已经进行了大量搜索,发现一篇文章指出 Chrome 存在 WebSocket 和 localhost 问题。有了这些知识,我编辑了主机文件,如下所示:
127.0.0.1 local.mydomain.com

comet.init() 的 url 变为 http:// /local.mydomain.com:8080/myapp/cometd/handshake。然而,这并没有解决问题,Chrome 也有同样的问题,但这次它看起来不喜欢指定的端口。我将本地应用程序更改为在端口 80 上运行,然后 url 变为 http://local.mydomain .com/myapp/cometd/handshake,但仍然没有骰子。

据我所知,cometd 2.0 通过在本机不支持 WebSocket 的浏览器(Firefox、IE 等)中使用长轮询来模拟 WebSocket,并在支持它的浏览器(Chrome)中使用 WebSocket,所以我猜测这就是我的问题的来源。

搜索还让我相信 WebSocket url 应该以 ws:// 而不是 http:// 开头,所以也许这是我的问题,但我不知道如何使用 tomcat/grails 进行配置。

有谁知道我该如何纠正我的问题?

Note: I've cross-posted this question in the grails-user mailing list

This weekend using this fantastic blog post as a guide and the cometd grails plug-in, I was able to get cometd installed with my existing grails app. Everything works perfectly in FireFox and IE (believe it or not) but I'm having issues with Google Chrome. From what I can tell it's happening on the comet.init() line in my javascript.

Using Chrome's developer tools, I'm seeing this error:
Wrong url scheme for WebSocket http://localhost:8080/myapp/cometd/handshake

I've done alot of searching, and found a post stating that Chrome has issues with WebSocket and the localhost. With that knowledge, I edited my hosts file to look something like:
127.0.0.1 local.mydomain.com

The url for comet.init() then becomes http://local.mydomain.com:8080/myapp/cometd/handshake. However, this did not correct the issue, and Chrome was having the same issue, but this time it looked like it didn't like the port being specified. I changed my local app to run on port 80, and the url then became http://local.mydomain.com/myapp/cometd/handshake, but still no dice.

From what I can tell, the cometd 2.0 emulates WebSocket by using long polling in browsers that don't support WebSocket natively (Firefox, IE, etc), and uses WebSocket in the browsers that do support it (Chrome), so I'm guessing that's where my issue is coming from.

Searching has also lead me to believe that WebSocket urls should start with ws:// instead of http://, so maybe that's my issue, but I do not know how to configure this with tomcat/grails.

Does anyone know how I can correct my issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不一样的天空 2024-10-14 02:42:30

我想我已经找到了一个临时解决办法,可以在我的 javascript 中使用这行代码: cometd.unregisterTransport('websocket');但我仍然很想知道将来如何在我的 grails 项目中使用 Websocket 协议

I think I've found a temporary work around using this line of code in my javascript: cometd.unregisterTransport('websocket'); But I'd still love to know how I could use the Websocket protocol with my grails project in the future

半透明的墙 2024-10-14 02:42:30

如果您使用 Grails 和 Cometd 插件,请确保您只从 Javascript 启用 websockets。您还应该将 Tomcat 插件替换为 Jetty 7 插件。请记住,如果您使用长轮询,您的配置 url 将以 http:// 或 https:// 开头,如果您使用 websockets,则它必须以 wss:// 开头。

尝试一下

var url = "";
if (Websocket === undefined) {
   url = "http://mydomain/myconext/cometd";
} else {
  url = "ws://mydomain/myconext/cometd";
} 

cometd.configure({
    url: url
});

我建议使用闪存桥。这比使用长轮询要快得多。请参阅下面的链接。
https://github.com/gimite/web-socket-js

If you are using Grails and the Cometd plugin make sure you just enable websockets from the Javascript. You shold also replace the Tomcat plugin with the Jetty 7 plugin. Keep in mind if you are using long polling your configure url will start with http:// or https:// if you are using websockets it must start with wss://.

try this

var url = "";
if (Websocket === undefined) {
   url = "http://mydomain/myconext/cometd";
} else {
  url = "ws://mydomain/myconext/cometd";
} 

cometd.configure({
    url: url
});

I wold recommended using a flash bridge. It would be a lot faster than using the long polling. See the link below.
https://github.com/gimite/web-socket-js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文