title: Establishing a WebSocket client connection in Jetty?
body: <p>I'm following this tutorial to establish a WebSocket connection to a server: 
  <a href="http://www.eclipse.org/jetty/documentation/current/jetty-websocket-client-api.html" rel="nofollow">http://www.eclipse.org/jetty/documentation/current/jetty-websocket-client-api.html</a></p>
  
  <p>The code (same as the tutorial): </p>
  
  <pre><code>import java.net.URI;
  import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
  import org.eclipse.jetty.websocket.client.WebSocketClient;
  
  /**
   * Example of a simple Echo Client.
   */
  public class SimpleEchoClient {
  
      public static void main(String[] args) {
          String destUri = "ws://echo.websocket.org";
          if (args.length &gt; 0) {
              destUri = args[0];
          }
          WebSocketClient client = new WebSocketClient();
          SimpleEchoClient socket = new SimpleEchoClient();
  
          try {
              client.start();
              URI echoUri = new URI(destUri);
              ClientUpgradeRequest request = new ClientUpgradeRequest();
              client.connect(socket, echoUri, request);
              System.out.printf("Connecting to : %s%n", echoUri);
             // socket.awaitClose(5, TimeUnit.SECONDS);
          } catch (Throwable t) {
              t.printStackTrace();
          } finally {
              try {
                  client.stop();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  
  }
  </code></pre>
  
  <p>Errors:</p>
  
  <pre class="lang-none prettyprint-override"><code>2014-08-07 21:49:00.346:INFO::main: Logging initialized @86ms
  org.eclipse.jetty.websocket.api.InvalidWebSocketException:
  SimpleEchoClient is not a valid WebSocket object.  
  Object must obey one of the following rules:  
  (1) class implements org.eclipse.jetty.websocket.api.WebSocketListener or  
  (2) class is annotated with @org.eclipse.jetty.websocket.api.annotations.WebSocket
  
  at org.eclipse.jetty.websocket.common.events.EventDriverFactory.wrap(EventDriverFactory.java:145)
  at org.eclipse.jetty.websocket.client.WebSocketClient.connect(WebSocketClient.java:200)
  at org.eclipse.jetty.websocket.client.WebSocketClient.connect(WebSocketClient.java:144)
  at SimpleEchoClient.main(SimpleEchoClient.java:31)
  </code></pre>
  
  <p>I'm not too sure what is wrong with my imported jar file. Maybe it is the wrong one? I'm using this: <a href="http://mvnrepository.com/artifact/org.eclipse.jetty.websocket/websocket-client/9.2.2.v20140723" rel="nofollow">http://mvnrepository.com/artifact/org.eclipse.jetty.websocket/websocket-client/9.2.2.v20140723</a></p>
  
  <p>Surely there must be an easier way to establish a connection via Jetty Websocket and start receiving data? </p>