title: Vertx Websockets starts encoding-decoding in loop after connecting second client
body: <p>I have simple Vertx-based websocket chatting app. It consists of two parts MsgServerVerticle and MsgClientVerticle (source code below). So, if I am instantiating one server and only one client it looks like working normally. After second client connects, server starts trying to announce it to other clients. And things gonna weird. Log says that netty backed are encoding-decoding websocket frames continuously in loop. There is no difference what type of frames I am using, binary or text, issues are the same.
  <a href="https://imgur.com/a/CsqTT" rel="nofollow noreferrer" title="log file screenshot">log screenshot here</a></p>
  
  <p>What's wrong?</p>
  
  <p>MsgClientVerticle Source code:</p>
  
  <pre><code>private Logger L;
  
  private String eBusTag;
  private String backwardTag;
  private String targetHost;
  private int port;
  private String id;
  private String path;
  
  private EventBus eBus;
  
  private HttpClient client;
  
  public MsgClientVerticle(String eBusTag, String targetHost, int port, String path, String id, String backwardTag) {
      this.eBusTag = eBusTag;
      this.targetHost = targetHost;
      this.path = path;
      this.port = port;
      this.id = id;
      this.backwardTag = backwardTag;
  
      L = LoggerFactory.getLogger(eBusTag);
  }
  
  @Override
  public void start(Future&lt;Void&gt; startFuture) throws Exception {
      L.info("Initializing client connection to " + targetHost + ":" + port + path);
      eBus = vertx.eventBus();
  
      try {
  
  
          client = vertx.createHttpClient();
  
          client.websocket(port, targetHost, path, webSock -&gt; {
              L.info("Connected to " + targetHost + ":" + port + "/" + path);
              eBus.publish(backwardTag, Utils.msg("Connected"));
              webSock.binaryMessageHandler(buf -&gt; {
                  eBus.publish(backwardTag, Utils.bufToJson(buf));
              });
              eBus.consumer(eBusTag).handler(msg -&gt; {
                  JsonObject message = (JsonObject) msg.body();
                  webSock.writeBinaryMessage(Utils.jsonToBuf(message));
              });
          });
      } catch (NullPointerException e) {
          L.error("Null Pointer: " + e.getLocalizedMessage());
          e.printStackTrace();
      }
  
  
      startFuture.complete();
  }
  
  @Override
  public void stop(Future&lt;Void&gt; stopFuture) throws Exception {
      L.info("Connection to " + targetHost + ":" + port + "/" + path + " closed");
      client.close();
      stopFuture.complete();
  }
  </code></pre>
  
  <p>And MsgServerVerticle source: </p>
  
  <pre><code>private Logger L;
  
  private String path;
  private int port;
  private String eBusTag;
  private String backwardTag;
  
  private HttpServer server;
  
  private EventBus eBus;
  
  private Set&lt;ServerWebSocket&gt; conns;
  
  public MsgServerVerticle(int port, String eBusTag, String backwardTag) {
      this.port = port;
      this.eBusTag = eBusTag;
      this.backwardTag = backwardTag;
  
      conns = new ConcurrentSet&lt;&gt;();
      path = eBusTag;
  
      L = LoggerFactory.getLogger(eBusTag);
  
  }
  
  @Override
  public void start(Future&lt;Void&gt; startFuture) throws Exception {
      eBus = vertx.eventBus();
      L.info("Initializing server instance at port " + port);
  
      server = vertx.createHttpServer();
  
      server.websocketHandler(webSock -&gt; {
  
          if (!webSock.path().equals(path)) {
  
              webSock.reject();
  
          } else {
  
              conns.add(webSock);
  
              conns.forEach(sock -&gt; {
                  if (sock != webSock) {
                      sock.writeBinaryMessage(Utils.jsonToBuf(Utils.msg("SERVER: new client " + webSock.remoteAddress().toString())));
                  }
              });
  
              eBus.publish(backwardTag, Utils.msg("SERVER: new client " + webSock.remoteAddress().toString()));
  
              webSock.binaryMessageHandler(buf -&gt; {
                  JsonObject msg = Utils.bufToJson(buf);
                  conns.forEach(sock -&gt; {
                      if (sock != webSock) {
                          sock.writeBinaryMessage(buf);
                      }
                  });
                  eBus.publish(backwardTag, msg);
              });
  
          }
  
      });
  
      server.listen(port);
  
      startFuture.complete();
  }
  
  @Override
  public void stop(Future&lt;Void&gt; stopFuture) throws Exception {
      conns.forEach(sock -&gt; {
          sock.writeFinalTextFrame("Server is shutting down...");
      });
      server.close();
      stopFuture.complete();
  }
  </code></pre>