use of okhttp3.WebSocket in project okhttp by square.
the class WebSocketHttpTest method readTimeoutAppliesToHttpRequest.
@Test
public void readTimeoutAppliesToHttpRequest() {
webServer.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE));
WebSocket webSocket = newWebSocket();
clientListener.assertFailure(SocketTimeoutException.class, "timeout", "Read timed out");
assertThat(webSocket.close(1000, null)).isFalse();
}
use of okhttp3.WebSocket in project java-sdk by watson-developer-cloud.
the class SpeechToTextTest method testClosingInputStreamClosesWebSocket.
@Test
public void testClosingInputStreamClosesWebSocket() throws Exception {
TestRecognizeCallback callback = new TestRecognizeCallback();
WebSocketRecorder webSocketRecorder = new WebSocketRecorder("server");
PipedOutputStream outputStream = new PipedOutputStream();
InputStream inputStream = new PipedInputStream(outputStream);
server.enqueue(new MockResponse().withWebSocketUpgrade(webSocketRecorder));
String customizationId = "id";
String version = "version";
Double customizationWeight = 0.1;
RecognizeOptions options = new RecognizeOptions.Builder().audio(inputStream).contentType(HttpMediaType.createAudioRaw(44000)).customizationId(customizationId).version(version).customizationWeight(customizationWeight).build();
service.recognizeUsingWebSocket(options, callback);
WebSocket serverSocket = webSocketRecorder.assertOpen();
serverSocket.send("{\"state\": {}}");
outputStream.write(ByteString.encodeUtf8("test").toByteArray());
outputStream.close();
webSocketRecorder.assertTextMessage("{\"content-type\":\"audio/l16; rate=44000\"," + "\"action\":\"start\"}");
webSocketRecorder.assertBinaryMessage(ByteString.encodeUtf8("test"));
webSocketRecorder.assertTextMessage("{\"action\":\"stop\"}");
webSocketRecorder.assertExhausted();
serverSocket.close(1000, null);
callback.assertConnected();
callback.assertDisconnected();
callback.assertNoErrors();
callback.assertOnTranscriptionComplete();
}
use of okhttp3.WebSocket in project java-sdk by watson-developer-cloud.
the class WebSocketRecorder method onFailure.
@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
Platform.get().log(Platform.INFO, "[WS " + name + "] onFailure", t);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onFailure(webSocket, t, response);
} else {
events.add(new Failure(t, response));
}
}
use of okhttp3.WebSocket in project java-sdk by watson-developer-cloud.
the class WebSocketRecorder method onOpen.
@Override
public void onOpen(WebSocket webSocket, Response response) {
Platform.get().log(Platform.INFO, "[WS " + name + "] onOpen", null);
WebSocketListener delegate = this.delegate;
if (delegate != null) {
this.delegate = null;
delegate.onOpen(webSocket, response);
} else {
events.add(new Open(webSocket, response));
}
}
use of okhttp3.WebSocket in project Fast-Android-Networking by amitshekhariitbhu.
the class WebSocketActivity method connectWebSocket.
private void connectWebSocket() {
OkHttpClient client = new OkHttpClient.Builder().readTimeout(0, TimeUnit.MILLISECONDS).build();
Request request = new Request.Builder().url("ws://echo.websocket.org").build();
webSocket = client.newWebSocket(request, getWebSocketListener());
}
Aggregations