I am using a physical device with android v4.4.2 (Java) with java_websockets and I get this error when attempting to connect to the websocket.
javax.net.ssl.SSLHandshakeException:
javax.net.ssl.SSLProtocolException:
SSL handshake aborted: ssl=0x7aa38588:
Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:
unknown protocol (external/openssl/ssl/s23_clnt.c:769 0x73a81cfc:0x00000000)
I have found this answer and I tried implementing it but nothing changes. That is where I get the code for NoSSLv3SocketFactory
. It goes into the try catch until the last line mWebSocketClient.connect()
but it doesn't go into the catch, the onError
logs the error.
This is the websocket setup code.
...
String complete = wsBase + ep;
URI uri = new URI(complete);
mWebSocketClient = new WebSocketClient(uri, new Draft_17())
{
@Override
public void onOpen(ServerHandshake serverHandshake)
{
Log.i("Websocket", "Opened");
}
@Override
public void onMessage(String s)
{
final String message = s;
runOnUiThread(new Runnable()
{
@Override
public void run()
{
Log.i("onMessage", "running");
}
});
}
@Override
public void onClose(int i, String s, boolean b)
{
Log.i("Websocket", "Closed " + s);
}
@Override
public void onError(Exception e)
{
Log.i("Websocket", "Error " + e.getMessage());
}
};
try
{
// Stuff I thought might have fixed it but didn't
SSLContext sslcontext = SSLContext.getInstance("TLSv1");
sslcontext.init(null,
null,
null);
SSLSocketFactory noSSLv3Factory = new NoSSLv3SocketFactory(sslcontext.getSocketFactory());
Socket socket = noSSLv3Factory.createSocket(uri.getHost(), 80);
mWebSocketClient.setSocket(socket);
mWebSocketClient.connect();
}
catch (Exception e)
{
Log.i("Websocket", e.getMessage());
}