use of com.koushikdutta.async.http.WebSocket.StringCallback in project AndroidAsync by koush.
the class WebSocketTests method testWebSocket.
public void testWebSocket() throws Exception {
final Semaphore semaphore = new Semaphore(0);
AsyncHttpClient.getDefaultInstance().websocket("http://localhost:5000/ws", null, new WebSocketConnectCallback() {
@Override
public void onCompleted(Exception ex, WebSocket webSocket) {
webSocket.send("hello");
webSocket.setStringCallback(new StringCallback() {
@Override
public void onStringAvailable(String s) {
assertEquals(s, "hello");
semaphore.release();
}
});
}
});
assertTrue(semaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS));
}
use of com.koushikdutta.async.http.WebSocket.StringCallback in project AndroidAsync by koush.
the class WebSocketTests method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
httpServer = new AsyncHttpServer();
httpServer.setErrorCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
fail();
}
});
httpServer.listen(AsyncServer.getDefault(), 5000);
httpServer.websocket("/ws", new WebSocketRequestCallback() {
@Override
public void onConnected(final WebSocket webSocket, AsyncHttpServerRequest request) {
webSocket.setStringCallback(new StringCallback() {
@Override
public void onStringAvailable(String s) {
webSocket.send(s);
}
});
}
});
}
Aggregations