This problem only occurs on Android 7!
In other versions the operation is perfect. And running tests on an S8 with smart network switching, by a friend's reports, is also working as it should.
Mine is a G5 Plus and has no way to turn off smart network switching.
At certain times it connects but most of the time it is not, and the error returned in IOException is Network is unreachable.
The piece of code where you run the error:
Socket clientSocket = new Socket();
try {
InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
clientSocket.connect(new InetSocketAddress(serverAddr, SERVERPORT), 20000); //<- aqui gera o erro
main.socket = clientSocket;
} catch (UnknownHostException e1) {
e1.printStackTrace();
Log.d("Artur",e1.getMessage());
} catch (IOException e1) {
e1.printStackTrace();
Log.d("Artur","Erro:"+e1.getMessage());
}