Socket.IO Android — HTTPS/SSL

Enable HTTPS secure connection to Socket.IO and Android

Aslam Anver
2 min readJul 5, 2020

If you are going through the Socket.IO HTTPS connection issue on Android by following the Socket.IO official tutorial https://socket.io/blog/native-socket-io-and-android.

You have to do some changes to your project to make it work.

First of all, if you have followed the above official reference from Socket.IO you might have included the library as below which is no longer valid.

implementation 'com.github.nkzawa:socket.io-client:0.6.0

It seems the Socket.IO official documentation is not that much updated.

You need to implement the below library instead of the above one.

👍implementation 'io.socket:socket.io-client:1.0.0'

Then you are good to import or replace the imported libraries from the previous one and just make sure your project works with HTTP well as earlier.

Finally, you have to set the HTTPS context and OkHttpClient to your IO options, in order to complete this you can copy the helper class which I’ve hosted in Gist.

Simply you can now pass the Socket Options to the set() method to set all the SSL context which enables your Socket.IO to communicate with HTTPS servers.

SocketSSL.set(options);

Here is a working example for your reference.

IO.Options options = new IO.Options();
SocketSSL.set(options);
Socket mSocket = IO.socket("https://abc.com", options);
mSocket.on("message", onNewMessage);
mSocket.connect();

Thank you ✌️ I’m Aslam Anver find me on GitHub and StackOverflow as aslamanver & Googlian

--

--

Aslam Anver

Passionate in AI Deep Learning, Find me on GitHub & StackOverflow