Created
November 14, 2016 05:14
-
-
Save abhirockzz/aaf00d2faf87b6731b7b694acb14b884 to your computer and use it in GitHub Desktop.
Timeouts in WebSocket with SendHandler (calback)
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
.... | |
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