use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketRecorder method onMessage.
@Override
public void onMessage(WebSocket webSocket, String text) {
Platform.get().log(Platform.INFO, "[WS " + name + "] onMessage", null);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onMessage(webSocket, text);
} else {
Message event = new Message(text);
events.add(event);
}
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketRecorder method onMessage.
@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
Platform.get().log(Platform.INFO, "[WS " + name + "] onMessage", null);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onMessage(webSocket, bytes);
} else {
Message event = new Message(bytes);
events.add(event);
}
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method readTimeoutAppliesToHttpRequest.
@Test
public void readTimeoutAppliesToHttpRequest() throws IOException {
webServer.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE));
WebSocket webSocket = newWebSocket();
clientListener.assertFailure(SocketTimeoutException.class, "timeout");
assertFalse(webSocket.close(1000, null));
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method clientCancelsIfCloseIsNotAcknowledged.
/** https://github.com/square/okhttp/issues/2788 */
@Test
public void clientCancelsIfCloseIsNotAcknowledged() throws Exception {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
RealWebSocket webSocket = newWebSocket();
clientListener.assertOpen();
WebSocket server = serverListener.assertOpen();
// Initiate a close on the client, which will schedule a hard cancel in 500 ms.
long closeAtNanos = System.nanoTime();
webSocket.close(1000, "goodbye", 500);
serverListener.assertClosing(1000, "goodbye");
// Confirm that the hard cancel occurred after 500 ms.
clientListener.assertFailure();
long elapsedUntilFailure = System.nanoTime() - closeAtNanos;
assertEquals(500, TimeUnit.NANOSECONDS.toMillis(elapsedUntilFailure), 250d);
// Close the server and confirm it saw what we expected.
server.close(1000, null);
serverListener.assertClosed(1000, "goodbye");
}
use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method binaryMessage.
@Test
public void binaryMessage() throws IOException {
webServer.enqueue(new MockResponse().withWebSocketUpgrade(serverListener));
WebSocket webSocket = newWebSocket();
clientListener.assertOpen();
serverListener.assertOpen();
webSocket.send(ByteString.encodeUtf8("Hello!"));
serverListener.assertBinaryMessage(ByteString.of(new byte[] { 'H', 'e', 'l', 'l', 'o', '!' }));
}
Aggregations