I'm trying to get response of an audio byte array from WebSocketApi by sending it through Okhttp3-(WebSocketListener). But am getting EOFException in onFailure() of WebSocketListener while sending audio byte array.
My code:
//Establishing connection with WS api
client = new OkHttpClient();
listener = new EchoWebSocketListener();
request = new Request.Builder().url("ws://AUDIO_PROCESSING_URL").build();
ws = client.newWebSocket(request, listener);
client.dispatcher().executorService().shutdown();
// Sending audio byte array to WS api
@Override
public void onOpen(WebSocket webSocket, Response response) {
String bytes = ByteString.of(AudioData).toString();
webSocket.send(bytes);
}
//ERROR
: onFailure: java.io.EOFException
: onFailure t.getMessage(): null
Please help me to find it out.
Thanks in advance.
try to close the connection after sending the data instead of shutting down the client.
public void onOpen(WebSocket webSocket, Response response) {
String bytes = ByteString.of(AudioData).toString();
webSocket.send(bytes);
webSocket.close(1000, null); // close ws connection
}