我在 Wildfly 上开发了我们的 websocket 项目。当我们在 localhost 或本地网络中对其进行测试时,一切正常。但是当我在 AWS 上部署它时,websocket 不再工作了。我们可以访问其他html页面。但是当我们连接到“ws://ip/project location”时,chrome只会说握手错误。我在jelastic托管上也遇到过同样的网络套接字问题。我的问题是
- 为什么会这样?
- websocket协议不够稳定?
- java中有没有合适的websocket项目托管?
我在 Wildfly 上开发了我们的 websocket 项目。当我们在 localhost 或本地网络中对其进行测试时,一切正常。但是当我在 AWS 上部署它时,websocket 不再工作了。我们可以访问其他html页面。但是当我们连接到“ws://ip/project location”时,chrome只会说握手错误。我在jelastic托管上也遇到过同样的网络套接字问题。我的问题是
到目前为止,平衡器不转发 websocket 标头。要使 WS 工作,您必须有一个公共 IP 地址,并且在您的应用程序前面没有其他服务。
我建议您尝试部署到云提供商:Heroku - 他们使用 node.js 和 websockets 的示例应用程序代码将使您快速启动并运行。使用特定端口的本地运行的 websocket 应用程序 - 比如说 8888 将在 heroku 上运行良好:
var port = process.env.PORT || 8888;
因为 heroku 在内部将使用通过 PORT 可见的运行时生成的端口部署您的应用程序。如果您将 node.js 与 websockets 一起使用,我建议使用 einaros ws 实现
var WebSocketServer = require("ws").Server;
无缝处理 ws 端口 -vs- http 端口的概念
Currently ELB doesn't support Websocket in HTTP mode. To be able to handle Websocket you need to configure the ELB in tcp mode (the payload of the tcp connection will be send directly to the server, so the ELB doesn't impact the http and ws flow). With this set up you won't be able to see the caller ip.
Without the ELB Websocket works perfectly (AWS only sees ip traffic and the OS only tcp one), we haven't change any thing for a plain old http server in order to use WS (except the WS handling code in the web server).
To know if you are using ELB look at the bill, AWS can provide you a lot of very interesting services, for a fee.