Created
June 17, 2016 09:36
-
-
Save abhirockzz/4cb001a2ff1eb6098f5c51824d41e239 to your computer and use it in GitHub Desktop.
Annotated Websocket Endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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