Skip to content

Instantly share code, notes, and snippets.

@gevorg
Created May 6, 2015 20:17
Show Gist options
  • Save gevorg/9ef7bd4418c0695a0a87 to your computer and use it in GitHub Desktop.
Save gevorg/9ef7bd4418c0695a0a87 to your computer and use it in GitHub Desktop.
AtmosphereClient usage
AtmosphereClient client = ClientFactory.getDefault().newClient(AtmosphereClient.class);
RequestBuilder request = client.newRequestBuilder()
.uri("ws://127.0.0.1:7070/test")
.transport(Request.TRANSPORT.WEBSOCKET);
Socket socket = client.create();
socket.on(Event.CLOSE.name(), new Function<String>() {
@Override
public void on(String t) {
System.out.println("CLOSED!");
}
}).on(Event.REOPENED.name(), new Function<String>() {
@Override
public void on(String t) {
System.out.println("REOPENED!");
}
}).on(new Function<IOException>() {
@Override
public void on(IOException ioe) {
ioe.printStackTrace();
}
}).on(Event.MESSAGE.name(), new Function<String>() {
@Override
public void on(String m) {
System.out.println("CMSG: " + m);
}
}).on(Event.OPEN.name(), new Function<String>() {
@Override
public void on(String t) {
System.out.println("OPEN!");
}
}).open(request.build());
socket.fire("BUUBA");
Thread.sleep(1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment