WebSockets在本地服务器中正常工作,但在Pivotal云上部署时失败

时间:2016-04-04 06:56:50

标签: cloudfoundry spring-websocket pivotal-cloud-foundry

当我在本地服务器上部署时,它工作正常,可以在任何浏览器上正常工作,但是当我在Pivotal云上部署时,它会在控制台日志下面失败:

Console.log错误:

WebSocket connection to 'wss://bmwbics.apps.pivotal.com/connect/sockjs/735/l8r_friu/websocket' failed: One or more reserved bits are on: reserved1 = 0, reserved2 = 1, reserved3 = 1

更新其他开发者有像我这样的问题。 我已经设置了错误的url_prefix来初始化SocketJS。

目前,我没有关键的url_prefix和我的本地之间的区别。

之后我更新了获取url_prefix作为下面代码的方式,它运行正常。

Javascript代码:

var protocol = location.protocol;
var hostname = location.hostname;
var port = location.port;
var url_prefix = protocol + "//" + hostname + (port === '' ? '' : ':' + port) + contextPath;
var sock = new SockJS(url_prefix + '/connectsocket');

Java配置代码:

@Configuration
@EnableWebSocket
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
   private static final int MESSAGE_SIZE_LIMIT = 1024 * 1024;
   private static final int SEND_BUFFER_SIZE_LIMIT = 1024 * 1024;
   private static final int SEND_TIME_LIMIT = 10 * 10000;
   @Override
   public final void registerStompEndpoints(final StompEndpointRegistry registry) {
      registry.addEndpoint("/connectsocket").withSockJS();
   }
   @Override
   public final void configureMessageBroker(final MessageBrokerRegistry config) {
      config.enableSimpleBroker("/topic");
      config.setApplicationDestinationPrefixes("/");
   }
   @Override
   public final void configureWebSocketTransport(final WebSocketTransportRegistration registration) {
      registration.setMessageSizeLimit(MESSAGE_SIZE_LIMIT);
      registration.setSendBufferSizeLimit(SEND_BUFFER_SIZE_LIMIT);
      registration.setSendTimeLimit(SEND_TIME_LIMIT);
   }
}

0 个答案:

没有答案