Skip to content

Instantly share code, notes, and snippets.

@Kotlin-Native
Created July 10, 2015 08:04
Show Gist options
  • Select an option

  • Save Kotlin-Native/94010df73d8b0960464e to your computer and use it in GitHub Desktop.

Select an option

Save Kotlin-Native/94010df73d8b0960464e to your computer and use it in GitHub Desktop.
public class MyWebSocketApplication extends WebSocketApplication {
public boolean isApplicationRequest(Request request) {
// determine if this application is responsible for this websocket request (identification by incoming request)
return request.toString().contains("/mywebsocketapp/myspecializedsocket/do.connect");
}
public WebSocket createWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) {
// create a new WebSocket and add it to the list of Sockets hold by this app
WebSocket socket = new MyWebSocket(protocolHandler, listeners);
add(socket);
return socket;
}
public void notifyOpenSockets(String message) {
// call this method to send a message to all connected WebSockets of this app
for (WebSocket socket: getWebSockets()) {
if (socket.isConnected()) {
socket.send(message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment