【问题标题】:How to send message to the @ServerEndpoint from .class如何从.class 向@ServerEndpoint 发送消息
【发布时间】:2020-10-11 07:19:46
【问题描述】:

我不知道如何向@ServerEndpoint 发送消息。我想从不同的项目向包含@ServerEndpoint 的项目发送消息。 @ServerEndpoint 代码如下...

@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);
    }
    
}

所以,我想通过另一个项目类触发 onMessage 函数。我怎样才能做到这一点? 另外,我不想使用javascript!我想用java语言交流。

【问题讨论】:

标签: java sockets websocket glassfish endpoint


【解决方案1】:

@ClientEndpoint 注解解决了这个问题。链接:ServerEndpoint

【讨论】:

    猜你喜欢
    • 2021-03-07
    • 2012-07-03
    • 1970-01-01
    • 2015-07-31
    • 2019-11-06
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多