title: Simple Websocket Client in Java - Connection issue
body: <p>I'm trying to write a simple websocket client in Java to connect to a 3rd party WebSocket server (I have no access to the server).</p>
  
  <p>I can connect and communicate with the websocket server using javascript in a browser, but when I try and do the same thing using a Java client it fails to connect.</p>
  
  <p>With the same java client I can connect to a tomcat websocket server I have running, so I think it's some sort of compatibility issue between the client and server.  (I'm using Tomcat 7.0.56 libraries for the websocket client).</p>
  
  <p>This is the error I get...</p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>javax.websocket.DeploymentException: The HTTP request to initiate the WebSocket connection failed
      at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:344)
      at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:166)
      at com.cvr.instant.ws.WebSocketClient.Connect(WebSocketClient.java:44)
      at com.cvr.instant.ws.TestWS.Start(TestWS.java:17)
      at com.cvr.instant.ws.TestWS.main(TestWS.java:37)
  Caused by: java.io.EOFException
      at org.apache.tomcat.websocket.WsWebSocketContainer.processResponse(WsWebSocketContainer.java:595)
      at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:317)
  ... 4 more
  </code></pre>
  
  <p><strong>WebSocketClient</strong></p>
  
  <pre><code>import java.io.IOException;
  import java.net.URI;
  import java.net.URISyntaxException;
  
  import javax.websocket.ClientEndpoint;
  import javax.websocket.CloseReason;
  import javax.websocket.ContainerProvider;
  import javax.websocket.DeploymentException;
  import javax.websocket.OnClose;
  import javax.websocket.OnMessage;
  import javax.websocket.OnOpen;
  import javax.websocket.Session;
  import javax.websocket.WebSocketContainer;
  
  @ClientEndpoint
  public class WebSocketClient {
  
      protected   WebSocketContainer container;
      protected   Session userSession = null;
  
      public WebSocketClient() {
          container = ContainerProvider.getWebSocketContainer();
      }
  
      public void Connect(String sServer) {
  
            try {
                userSession = container.connectToServer(this, new URI(sServer));
  
              } catch (DeploymentException | URISyntaxException | IOException e) {
                  e.printStackTrace();
              }
  
      }
  
      public void SendMessage(String sMsg) throws IOException {
          userSession.getBasicRemote().sendText(sMsg);
      }
  
      @OnOpen
      public void onOpen(Session session) {
          System.out.println("Connected");
      }
  
      @OnClose
      public void onClose(Session session, CloseReason closeReason) {
      }
  
      @OnMessage
      public void onMessage(Session session, String msg) {
          System.out.println(msg);
      }
  
      public void Disconnect() throws IOException {
          userSession.close();
      }
  }
  </code></pre>
  
  <p><strong>Running the client</strong></p>
  
  <pre><code>import java.io.IOException;
  
  public class TestWS {
  
      public WebSocketClient wsc;
      public TestWS() {
      }
  
      public void Start() throws InterruptedException, IOException {
  
          wsc = new WebSocketClient();
          wsc.callback = this;
          wsc.Connect("ws://192.168.0.25:9000");
          Thread.sleep(1000);
          wsc.Disconnect();
      }
  
  
      public static void main(String[] args) throws InterruptedException, IOException 
      {
          TestWS t = new TestWS();
          t.Start();
          Thread.sleep(1000);
      }
  
  }    
  </code></pre>
  
  <p>I'm very new to websocket clients (and fairly new to websockets in general).  Any help you can give would be appreciated!</p>