Created
January 5, 2016 20:50
-
-
Save activetheory/235b4410d38730bf0bf0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private void setup() { | |
AsyncServer.getDefault().connectSocket(_host, new ConnectCallback() { | |
@Override | |
public void onConnectCompleted(Exception ex, final AsyncSocket socket) { | |
handleConnectCompleted(ex, socket); | |
} | |
}); | |
} | |
private void handleConnectCompleted(Exception ex, final AsyncSocket socket) { | |
if(ex != null) throw new RuntimeException(ex); | |
_server = socket; | |
socket.setDataCallback(new DataCallback() { | |
@Override | |
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) { | |
String message = new String(bb.getAllByteArray()); | |
_parent.receiveFromServer(message); | |
} | |
}); | |
socket.setClosedCallback(new CompletedCallback() { | |
@Override | |
public void onCompleted(Exception ex) { | |
if(ex != null) throw new RuntimeException(ex); | |
} | |
}); | |
socket.setEndCallback(new CompletedCallback() { | |
@Override | |
public void onCompleted(Exception ex) { | |
if(ex != null) throw new RuntimeException(ex); | |
} | |
}); | |
_parent.connectionEstablished(); | |
} | |
public void send(String message) { | |
_server.write(ByteBuffer.wrap(message.getBytes())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment