0

When I try to execute the following code for Websocket in Okhttp, I get an error message:

Caused by: java.lang.IllegalArgumentException: unexpected 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();
            }
        });

1 Answer 1

1

its not WWS, but WSS. Change your url to String WEBSOCKET_URL = "wss://www.mydomain.com/websocket";

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.