我有运行在TomCat上的简单WebSocket服务器:
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/MyApi")
public class WsServer {
@OnOpen
public void onOpen(){
System.out.println("Open Connection ...");
}
@OnClose
public void onClose(){
System.out.println("Close Connection ...");
}
@OnMessage
public String onMessage(String message){
System.out.println( message);
String echoMsg = "answer";
return echoMsg;
}
@OnError
public void onError(Throwable e){
e.printStackTrace();
}
}
我从客户端收到消息,但我不想回应
@OnMessage
public String onMessage(String message){
System.out.println( message);
String echoMsg = "";
return echoMsg;
}
如果我设置了空的响应字符串,服务器将发送带有空字符串的响应数据包。如何阻止服务器发回所有数据包?