Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created June 17, 2016 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/4cb001a2ff1eb6098f5c51824d41e239 to your computer and use it in GitHub Desktop.
Save abhirockzz/4cb001a2ff1eb6098f5c51824d41e239 to your computer and use it in GitHub Desktop.
Annotated Websocket Endpoint
//imports ommitted
@ServerEndpoint("/testwsep")
public class MyWsendpoint {
static Set<Session> clients = new HashSet<Session>();
@OnOpen
public void open(Session s) {
clients.add(s);
}
@OnMessage
public void msg(String m) {
for (Session client : clients) {
try {
client.getBasicRemote().sendText("Catch this! "+ m);
} catch (IOException ex) {
Logger.getLogger(MyWsendpoint.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
//.. other callback methods ommitted - @onClose, @onError
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment