Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nurettin/0421fc97c62480cdac998f0577fa0968 to your computer and use it in GitHub Desktop.
Save nurettin/0421fc97c62480cdac998f0577fa0968 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