title: Apache Tomcat websockets server side messages
body: <p>I have successfully implemented an simple echo server example for tomcat websockets. now I need to send continuous messages to the client from my server. How do I achieve this??</p>
  
  <p>Present server side code</p>
  
  <pre><code>package org.playjava.websocket;
  
  import java.io.IOException;
  import java.nio.ByteBuffer;
  import java.nio.CharBuffer;
  import javax.servlet.http.HttpServletRequest;
  import org.apache.catalina.websocket.MessageInbound;
  import org.apache.catalina.websocket.StreamInbound;
  import org.apache.catalina.websocket.WebSocketServlet;
  import org.apache.catalina.websocket.WsOutbound;
  
  public class SimpleEchoServlet extends WebSocketServlet {
  
      @Override
      protected StreamInbound createWebSocketInbound(String string, HttpServletRequest hsr) {
          return new SimpleEchoInbound();
      }
  
      private static final class SimpleEchoInbound extends MessageInbound {
  
          public SimpleEchoInbound() {
              super();
          }
  
  
  
  
          @Override
          protected void onBinaryMessage(ByteBuffer message) throws IOException {
              getWsOutbound().writeBinaryMessage(message);
          }
  
          @Override
          protected void onTextMessage(CharBuffer message) throws IOException {
              getWsOutbound().writeTextMessage(message);
              getWsOutbound().writeTextMessage(message);
              getWsOutbound().writeTextMessage(message);
          }
  
  
  
      }
  }
  </code></pre>