I am creating an Android App which I want to connect to my server running secure websockets (wss). My code to connect is as below:
private void createWebSocketClient() { URI uri; try { // Connect to local host uri = new URI("wss://mysocketsdomain:8080/ws"); } catch (URISyntaxException e) { Log.d("Connection", "I am not even connecting"); e.printStackTrace(); return; } webSocketClient = new WebSocketClient(uri) { @Override public void onOpen() { Log.i("WebSocket", "Session is starting"); webSocketClient.send("Hello World!"); } @Override public void onTextReceived(String s) { Log.i("WebSocket", "Message received"); final String message = s; runOnUiThread(new Runnable() { @Override public void run() { try{ //TextView textView = findViewById(R.id.mainText); //textView.setText(message); } catch (Exception e){ e.printStackTrace(); } } }); } @Override public void onBinaryReceived(byte[] data) { } @Override public void onPingReceived(byte[] data) { } @Override public void onPongReceived(byte[] data) { } @Override public void onException(Exception e) { System.out.println(e.getMessage()); } @Override public void onCloseReceived() { Log.i("WebSocket", "Closed "); System.out.println("onCloseReceived"); } }; webSocketClient.setConnectTimeout(10000); webSocketClient.setReadTimeout(60000); webSocketClient.enableAutomaticReconnection(5000); webSocketClient.connect(); } I am getting the error below:
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. The connection works fine if I visit the web front end from a browser and I can see that the certificate is valid from the padlock symbol. Also, the frontend web app that I developed using Svelte in JavaScript works fine.
Can anyone advise what I need to do? I am reading a lot of confusing information online. Some things suggest that I need to create a trusted certificate store in the Android app. Another thing that I saw suggested it is a problem with the server certificate chain. I set the server to use the certificate file containing the chain, but the error still happens. I am not sure if it would be the server when it works for the JavaScript app and the web front end.
https://stackoverflow.com/questions/66828486/certificate-error-when-using-tech-gusavila92-websocketclient-websocketclient March 27, 2021 at 02:05PM
没有评论:
发表评论