这是一个文件,我在 import javax.websocket
和 @serverEndpoint("/websocket")
两行代码中遇到了编译错误。为什么这个注释没有被识别?请帮我检查一下。
package pack.exp;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/websocket")
public class Hello
{
{
private static Set<Session> clients =
Collections.synchronizedSet(new HashSet<Session>());
@OnMessage
public void onMessage(String message, Session session)
throws IOException {
synchronized(clients){
// Iterate over the connected sessions
// and broadcast the received message
for(Session client : clients){
if (!client.equals(session)){
client.getBasicRemote().sendText(message);
}
}
}
}
@OnOpen
public void onOpen (Session session) {
// Add session to the connected sessions set
clients.add(session);
}
@OnClose
public void onClose (Session session) {
// Remove session from the connected sessions set
clients.remove(session);
}
}
}
请帮我处理这个错误。在这段代码中有一些特定的API需要实现吗?