title: Sending messages from Android Websocket client
body: <p>I want to send a message from Android okhttp3 websocket client, not just echoing the messages coming from the server. here is my websocket class:</p>
  <pre><code> // Websocket
   public final class EchoWebSocketListener extends WebSocketListener {
       private static final int NORMAL_CLOSURE_STATUS = 1000;
       @Override
       public void onOpen(WebSocket webSocket, Response response) {
           webSocket.send(message);
       }
       @Override
       public void onMessage(WebSocket webSocket, String text) {
           printer(&quot;text&quot;);
       }
       @Override
       public void onClosing(WebSocket webSocket, int code, String reason) {
           webSocket.close(NORMAL_CLOSURE_STATUS, null);
       }
       @Override
       public void onFailure(WebSocket webSocket, Throwable t, Response response) {
  
       }
       public void send(WebSocket webSocket) {
         webSocket.send(finalMessage);
       }
   }
  </code></pre>
  <p>And here is how I call it from the onCreate method:</p>
  <pre><code>client= new OkHttpClient();
  Request request = new Request.Builder().url(Url).build();
  EchoWebSocketListener listener = new EchoWebSocketListener();
  webso = myClient.newWebSocket(request, listener);
  client.dispatcher().executorService().shutdown();
  </code></pre>
  <p>I tried to make an object to the class and call a function I named it 'send':</p>
  <pre><code>EchoWebSocketListener object = new EchoWebSocketListener ()
  object.send(webso)
  </code></pre>
  <p>But that's not working?</p>