[英]how to specify websocket encoder and decoder to simple class
I am writing a simple websocket application. 我正在编写一个简单的websocket应用程序。 In this I separate out the message sending functionality.
在此,我分离出消息发送功能。 More clearly
onOpen, onClose, onMessage, onError
etc methods are placed in the class which annotated with @ServerEndpoint
ie 更清楚的是,将
onOpen, onClose, onMessage, onError
等方法放置在以@ServerEndpoint
注释的类中,即
@ServerEndpoint(value = "/test")
public class TestEndpoint {
@OnOpen
public void onOpen(Session session) throws IOException {
}
@OnMessage
public String echo(String message) {
}
@OnError
public void onError(Throwable t) {
}
@OnClose
public void onClose(Session session) {
}
}
And I want to give responsibility of sending message object to the class MessageSender
, ie 我要负责将消息对象发送到
MessageSender
类,即
public class MessageSender {
/**
*
* This method will take care of sending messages object
*/
public void sendMessage(){
}
}
so MessageSender class should make use of websocket Encoder
and Decoder
class but as per my knowledge we can use Encoders
and Decoders
only in @ServerEndpoint
annotation 所以MessageSender类应该使用的WebSocket的
Encoder
和Decoder
类,但按我的知识,我们可以使用Encoders
和Decoders
只在@ServerEndpoint
注释
like, 喜欢,
@ServerEndpoint(value = "/test", encoder = Encoder.class, decoders = Decoder.class) @ServerEndpoint(值=“ / test”,编码器= Encoder.class,解码器= Decoder.class)
is there any way to use encoder and decoder for simple class? 有什么方法可以将编码器和解码器用于简单的类?
Encoder
和Decoder
将应用于创建的Session
对象,因此,如果将其传递给MessageSender
类,然后执行诸如session.getBasicRemote().sendObject(…)
,它将使用在上定义的同一组编码器@ServerEndpoint
批注。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.