title: Can't connect client to server using Spring Websocket
body: <p>I've written a Blackjack server in java which starts up fine, but I'm having trouble writing a separate java client to connect to my server. I've followed the Spring Websocket documentation and examples and it looks like my client connects without any errors and I'd expect it to hit the <code>afterConnected()</code> method, but it doesn't get to that point. The client runs and finishes with no errors. Any idea what I'm doing wrong?</p>
  
  <p><strong>WebSocketConfig.java on the server side:</strong></p>
  
  <pre><code>package com.lactaoen.blackjack.config;
  
  import org.springframework.context.annotation.Configuration;
  import org.springframework.messaging.simp.config.MessageBrokerRegistry;
  import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
  import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
  import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
  
  @Configuration
  @EnableWebSocketMessageBroker
  public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
  
      @Override
      public void configureMessageBroker(MessageBrokerRegistry registry) {
          registry.enableSimpleBroker("/topic", "/queue");
          registry.setApplicationDestinationPrefixes("/app");
          registry.setUserDestinationPrefix("/user");
      }
  
      @Override
      public void registerStompEndpoints(StompEndpointRegistry registry) {
          registry.addEndpoint("/connect").withSockJS();
      }
  }
  </code></pre>
  
  <p><strong>Client side:</strong></p>
  
  <pre><code>package com.lactaoen.blackjack.client;
  
  import org.springframework.messaging.converter.StringMessageConverter;
  import org.springframework.messaging.simp.stomp.*;
  import org.springframework.web.socket.client.standard.StandardWebSocketClient;
  import org.springframework.web.socket.messaging.WebSocketStompClient;
  import org.springframework.web.socket.sockjs.client.RestTemplateXhrTransport;
  import org.springframework.web.socket.sockjs.client.SockJsClient;
  import org.springframework.web.socket.sockjs.client.Transport;
  import org.springframework.web.socket.sockjs.client.WebSocketTransport;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class BlackjackClient {
  
      public static void main(String[] args) {
  
          List&lt;Transport&gt; transports = new ArrayList&lt;&gt;();
          transports.add(new WebSocketTransport(new StandardWebSocketClient()));
          transports.add(new RestTemplateXhrTransport());
  
          SockJsClient sockJsClient = new SockJsClient(transports);
  
          String stompUrl = "ws://localhost:8080/connect";
          WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient);
          stompClient.setMessageConverter(new StringMessageConverter());
  
          stompClient.connect(stompUrl, new BlackjackSessionHandler());
      }
  
      private static class BlackjackSessionHandler extends StompSessionHandlerAdapter {
          @Override
          public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
              // I'd expect it to print this out, but it doesn't get here
              System.out.println("Hello, world!");
          }
      }
  }
  </code></pre>