Skip to content

Instantly share code, notes, and snippets.

@JoachimR
Created May 28, 2015 09:39
Show Gist options
  • Save JoachimR/13292d950c1f8580e54e to your computer and use it in GitHub Desktop.
Save JoachimR/13292d950c1f8580e54e to your computer and use it in GitHub Desktop.
Android Server Side Events
buildscript {
...
}
...
android {
...
}
dependencies {
...
compile 'org.kaazing:gateway.client.java:5.1.0.3'
}
try {
final SseEventSourceFactory sseEventSourceFactory = SseEventSourceFactory.createEventSourceFactory();
final SseEventSource sseEventSource = sseEventSourceFactory.createEventSource(new URI("http://my/event/url"));
sseEventSource.connect();
final SseEventReader sseEventReader = sseEventSource.getEventReader();
SseEventType type = sseEventReader.next();
while (type != SseEventType.EOS) {
log("new event");
if (type != null && type.equals(SseEventType.DATA)) {
CharSequence data = sseEventReader.getData();
log(data.toString());
} else {
log("type null or not data: " + type);
}
type = sseEventReader.next();
}
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment