Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created November 14, 2016 05:14
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/aaf00d2faf87b6731b7b694acb14b884 to your computer and use it in GitHub Desktop.
Save abhirockzz/aaf00d2faf87b6731b7b694acb14b884 to your computer and use it in GitHub Desktop.
Timeouts in WebSocket with SendHandler (calback)
....
public void broadcast(Session s, String msg){
RemoteEndpoint asyncHandle = s.getRemoteAsync();
asyncHandle.setSendTimeout(1000); //1 second
asyncHandle.sendText(msg,
new SendHandler(){
@Override
public void onResult(SendResult result) {
if(!result.isOK()){
System.out.println("Async send failure: "+ result.getException());
}
}
}); //will timeout after 2 seconds
tracker.get(); //will throw java.util.ExecutionException if the process had timed out
}
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment