我正在使用带有java_websockets的android v4.4.2(Java)的物理设备,并且在尝试连接到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)
我找到this answer并尝试实施但没有任何变化。这就是我获取NoSSLv3SocketFactory
代码的地方。它进入try catch直到最后一行mWebSocketClient.connect()
,但它没有进入catch,onError
记录错误。
这是websocket设置代码。
...
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());
}
答案 0 :(得分:0)
Socket socket = noSSLv3Factory.createSocket(uri.getHost(), 80);
如果我正确理解您的代码,您正尝试连接到端口80上的安全WebSocket。虽然理论上有人可以设置这样的服务器,但这种可能性很小。端口80用于http而不是https,因此对于ws://
而不是wss://. Secure Websockets (
wss://`)通常在端口443上处理,其中也完成了https。