Smack connection to Orbot - SOCKS 5 exception: stream is closed


I am using following code to connect to Orbot:

final Random rndForTorCircuits = new Random();

String user = rndForTorCircuits.nextInt(100000) + “”;

String pass = rndForTorCircuits.nextInt(100000) + “”;

ProxyInfo proxyInfo = new ProxyInfo(ProxyInfo.ProxyType.SOCKS5, “”, 9050, user, pass);

socket = new Socket();

if(Config.ONION_SERVER_PORT == 0){

proxyInfo.getProxySocketConnection().connect(socket, addr.getAddress(), addr.getPort(), Config.SOCKET_TIMEOUT*1000);

//socket = proxyInfo.getSocketFactory().createSocket(addr.getHostName(), addr.getPort());

proxyInfo.getProxySocketConnection().connect(socket, addr.getAddress(), Config.ONION_SERVER_PORT, Config.SOCKET_TIMEOUT*1000);

//socket = proxyInfo.getSocketFactory().createSocket(addr.getHostName(), Config.ONION_SERVER_PORT);

However I am getting SOCKS5: stream is closed exception. I am using Smack-4.2 library to get proxy socket connection. Yesterday I had implemented a bit different method using Smack4.1 proxyInfo socket factory. It worked perfectly and I was abble to connect. Yet after reconnecting wifi I was getting the same error. However phone restart helped and I was able to connect again. But today, after same error, even phone restart did not help. So I tried using Smack-4.2 but it is still not working.

Any ideas how to fix this? thanks in forward