它的工作原理,但你必須做一些修改io.socket庫。 而不是使用socketio.jar,導入到src文件夾中的io.socket庫(您會在socket.io-java-client包內找到)。在那裏,你必須編輯WebsocketTransport類。
在這裏,你有解決方案
https://github.com/Gottox/socket.io-java-client/issues/60
public WebsocketTransport(URI uri, IOConnection connection) {
super(uri);
this.connection = connection;
SSLContext context = null;
try {
context = SSLContext.getInstance("TLS", "HarmonyJSSE");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
try {
context.init(null, null, null);
} catch (KeyManagementException e) {
e.printStackTrace();
}
if("wss".equals(uri.getScheme()) && context != null) {
this.setWebSocketFactory(new DefaultSSLWebSocketClientFactory(context));
}
}
記住調用setDefaultSSLSocketFactory這樣的:
socket = new SocketIO();
socket.setDefaultSSLSocketFactory(SSLContext.getDefault());
socket.connect("https://www.myHttpsServer.com:443/");
希望它可以幫助別人;)
你可以分享你的代碼,你如何改變傳輸到只有websocket – 2017-02-28 11:19:00