0

I'm having problems to connect with socket.

This is the error i'm getting on browser. socket error

This is my 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(); } 

I'm using sockjs-client v1.0.3, running the java application in a tomcat 8, linux ec2 on aws.

Any help on how to solve this problem?

EDITED

On server, THe only log I see is "Handshake failed due to invalid Upgrade header: null"

1 Answer 1

1

Check your Apache httpd.conf to make sure your redirects are not causing the problem.

You should have something like the following:

RewriteEngine On RewriteCond %{HTTP:Upgrade} =websocket [NC] RewriteRule /(.*) ws://localhost:8080/$1 [P,L] RewriteCond %{HTTP:Upgrade} !=websocket [NC] 

Are you seeing this for WS & WSS?

Another possibility, especially if you're trying to communicate with secure sockets, is that your Apache proxy is trying to handle the security while passing unsecured content to your services. This will interfere with the handshaking that upgrades the http connection to a websocket, since once it's a websocket, Apache is bypassed. Instead, you should divert the socket to a secure port on your server (e.g. Tomcat, or whatever is hosting the websocket server) and let your server handle the upgrade.

Sign up to request clarification or add additional context in comments.

1 Comment

can you check my last question please

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.