title: Send messages from server to websocket clients
body: <p>I'm building a websocket application using glassfish I need in a given event my server to send message to all connected clients. I can send and receive messages from both, but I am not able to use the class server to send messages.</p>
  
  <p>My server class has the following body: </p>
  
  <p><code>@ApplicationScoped
   @ServerEndpoint("/actions")
  public class DeviceWebSocketServer {</code></p>
  
  <pre><code>@Inject
  private DeviceSessionHandler sessionHandler;
  
  @OnOpen
  public void open(Session session) {
      sessionHandler.addSession(session);
  }
  
  @OnClose
  public void close(Session session) {
      sessionHandler.removeSession(session);
  }
  
  @OnError
  public void onError(Throwable error) {
      Logger.getLogger(DeviceWebSocketServer.class.getName()).log(Level.SEVERE, null, error);
  }
  
  @OnMessage
  public void handleMessage(String message, Session session) {
  
      System.out.println("Chegou uma mensagem: " + message);
      System.out.println("Na sessao: " + session.getId());
  
      try (JsonReader reader = Json.createReader(new StringReader(message))) {
          JsonObject jsonMessage = reader.readObject();
  
          if ("add".equals(jsonMessage.getString("action"))) {
              Device device = new Device();
              device.setName(jsonMessage.getString("name"));
              device.setDescription(jsonMessage.getString("description"));
              device.setType(jsonMessage.getString("type"));
              device.setStatus("Off");
              sessionHandler.addDevice(device);
          }
  
          if ("remove".equals(jsonMessage.getString("action"))) {
              int id = (int) jsonMessage.getInt("id");
              sessionHandler.removeDevice(id);
          }
  
          if ("toggle".equals(jsonMessage.getString("action"))) {
              int id = (int) jsonMessage.getInt("id");
              sessionHandler.toggleDevice(id);
          }
      }
  
  }
  </code></pre>
  
  <p>How do I send messages to customers after receiving an event? Should I instantiate my class server?</p>