@Override
  @OnClose
  public void onClose(Session session, CloseReason closeReason) {

    try {
      if (tunnel != null) tunnel.close();
    } catch (GuacamoleException e) {
      logger.debug("Unable to close WebSocket tunnel.", e);
    }
  }
  @OnMessage
  public void onMessage(String message) {

    // Ignore inbound messages if there is no associated tunnel
    if (tunnel == null) return;

    GuacamoleWriter writer = tunnel.acquireWriter();

    try {
      // Write received message
      writer.write(message.toCharArray());
    } catch (GuacamoleConnectionClosedException e) {
      logger.debug("Connection to guacd closed.", e);
    } catch (GuacamoleException e) {
      logger.debug("WebSocket tunnel write failed.", e);
    }

    tunnel.releaseWriter();
  }