我遇到连接套接字的问题。
这是我在浏览器上遇到的错误。 socket error
这是我的spring socket config
@EnableWebSocketMessageBroker
public class ChatSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/queue", "/topic");
config.setApplicationDestinationPrefixes("/chat");
}
/**
* Register the endpoint where the socket will call to connect
*/
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/chat-connect").setAllowedOrigins("*").withSockJS();
}
我正在使用sockjs-client v1.0.3,在tomcat 8中运行java应用程序,在aws上运行linux ec2。
有关如何解决此问题的任何帮助?
EDITED
在服务器上,我看到的唯一日志是“由于升级头无效而握手失败:空”
答案 0 :(得分:0)
检查您的Apache httpd.conf以确保您的重定向不会导致问题。
您应该拥有以下内容:
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*) ws://localhost:8080/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
你是否看到了WS& WSS?
另一种可能性,特别是如果您尝试与安全套接字进行通信时,您的Apache代理正在尝试处理安全性,同时将不安全的内容传递给您的服务。这将干扰将http连接升级到websocket的握手,因为一旦它成为websocket,就会绕过Apache。相反,您应该将套接字转移到服务器上的安全端口(例如Tomcat,或托管websocket服务器的任何端口),并让服务器处理升级。