我有一个码头服务器,我按照https://examples.javacodegeeks.com/enterprise-java/jetty/jetty-websocket-example/
的说明操作我定义了一个@ServerEndpoint
:
@ServerEndpoint("/jsr356toUpper")
public class ToUpper356Socket {
@OnOpen
public void onOpen(Session session) {
System.out.println("WebSocket opened: " + session.getId());
}
@OnMessage
public void onMessage(String txt, Session session) throws IOException {
System.out.println("Message received: " + txt);
session.getBasicRemote().sendText(txt.toUpperCase());
}
@OnClose
public void onClose(CloseReason reason, Session session) {
System.out.println("Closing a WebSocket due to " + reason.getReasonPhrase());
}
}
但我明白了:
WebSocket握手期间出错:意外的响应代码:404 WrappedWebSocket @ VM222:161
当我尝试联系ws:// localhost:8080 / jsr356toUpper
有什么建议吗?
答案 0 :(得分:1)
解决了,显然我使用了一个旧的码头插件
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
而不是
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>