-1

I don't know how to send a message to the @ServerEndpoint. I want to send a message from different project to the project which contains @ServerEndpoint. @ServerEndpoint code below...

@ServerEndpoint("/posluzitelj")
@Stateless
public class Posluzitelj {
    static Queue<Session> queue = new ConcurrentLinkedQueue<>();

    public static void send(String message) {
       
    }

    @OnMessage
    public void onMessage(String message) {

    }

    @OnOpen
    public void openConnection(Session session) {
        queue.add(session);
    }

    @OnClose
    public void closedConnection(Session session) {
        queue.remove(session);
    }

    @OnError
    public void error(Session session, Throwable t) {
        queue.remove(session);
    }
    
}

So, I wanna trigger onMessage function via another project class. How can I do that? Also, I do not want to use javascript! I wanna make communication with java language.

Domagoj Hamzic
  • 300
  • 3
  • 17
  • Does this answer your question? [How to send a message through web socket to a connected user?](https://stackoverflow.com/questions/42804923/how-to-send-a-message-through-web-socket-to-a-connected-user) – Mykola Jun 21 '20 at 10:48
  • 1
    @MykolaMurza, unfortunately, no. I want to send a message to the socket endpoint. I know how to do that with js, for example: WebSocket ws=new WebSocket("ws://localhost:8084/application_1/posluzitelj"); – Domagoj Hamzic Jun 21 '20 at 10:52
  • 1
    Problem is solved with @ClientEndpoint annotation. Link: [@ClientEndpoint class implementation](https://stackoverflow.com/questions/26452903/javax-websocket-client-simple-example) – Domagoj Hamzic Jun 21 '20 at 13:17

1 Answers1

0

The problem is solved with @ClientEndpoint annotation. Link: ServerEndpoint

Domagoj Hamzic
  • 300
  • 3
  • 17