title: How can i connect to a WebSocket from a Java console program?
body: <p>I am new in Java.  I've created a simple WebSocket.</p>
  
  <pre><code>import javax.websocket.OnClose;
  import javax.websocket.OnMessage;
  import javax.websocket.OnOpen;
  import javax.websocket.Session;
  import javax.websocket.server.ServerEndpoint;
  import java.io.IOException;
  
  
  @ServerEndpoint("/RankixSocket")
  public class RankixSocket {
  
      @OnOpen
      public void onOpen(Session session) {
          try {
              session.getBasicRemote().sendText("Connected");
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      @OnMessage
      public void onMessage(Session session, String message) {
          System.out.println("New message : " + message);
          try {
              session.getBasicRemote().sendText("Message received -&gt; :" + message);
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      @OnClose
      public void onClose() {
          System.out.println("Closed");
      }
  
  }
  </code></pre>
  
  <p>Now i want to connect to the WebSocket from the console application. I've seen an <a href="http://www.androidhive.info/2014/10/android-building-group-chat-app-using-sockets-part-2/" rel="nofollow">example</a> of connecting to the <code>WebSocket</code> from <code>Android Application</code>. In that example the author used an <a href="https://github.com/koush/android-websockets" rel="nofollow">external library</a>. I've googled a lot but nothing found helpful :( . </p>
  
  <ol>
  <li>Is it possible to connect to a <code>WebSocket</code> from a normal Java console application ? then How can i do that? Is there any external libraries ?</li>
  </ol>
  
  <p>Any help will be appreciated. </p>