Created
May 28, 2015 09:39
-
-
Save JoachimR/13292d950c1f8580e54e to your computer and use it in GitHub Desktop.
Android Server Side Events
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
buildscript { | |
... | |
} | |
... | |
android { | |
... | |
} | |
dependencies { | |
... | |
compile 'org.kaazing:gateway.client.java:5.1.0.3' | |
} |
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
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