Когда я пытаюсь выполнить следующий код для Websocket в Okhttp, я получаю сообщение об ошибке:
Причина: java.lang.IllegalArgumentException: неожиданный URL: wws: //www.mydomain.com/websocket
String WEBSOCKET_URL = "wws://www.mydomain.com/websocket";
OkHttpClient client = new OkHttpClient.Builder()
.readTimeout(0, TimeUnit.MILLISECONDS)
.build();
Request request = new Request.Builder().url(WEBSOCKET_URL).build();
WebSocket webSocket = client.newWebSocket(request, new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, okhttp3.Response response) {
Toast.makeText(HomeCoach.this, "Connected to the Websocket server", Toast.LENGTH_SHORT).show();
}
@Override
public void onMessage(WebSocket webSocket, String text) {
super.onMessage(webSocket, text);
}
@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
super.onMessage(webSocket, bytes);
}
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
super.onClosed(webSocket, code, reason);
}
@Override
public void onFailure(WebSocket webSocket, Throwable t, @Nullable okhttp3.Response response) {
Toast.makeText(HomeCoach.this, "Error ", Toast.LENGTH_SHORT).show();
}
});