Simplified code:
Socket mysock = new Socket("192.168.1.1", 1234);
mysock.setSoTimeout(15000);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(mysock.getOutputStream())), true);
BufferedReader in = new BufferedReader(new InputStreamReader(mysock.getInputStream()));
out.println("some text here");
String response = in.readLine(); // <-- throws Read timed out exception.
On Android versions lower than 10 this code works correctly. And no exception is being thrown.
On Android version 10 readLine()
always throws an exception after 15s.
Am i doing something wrong with the socket streams?
Turns out phone was blocking the connection.
I am not sure if this is Android 10, or custom UI of the manufacturer that is doing this, but user had to click on a network and allow phone to complete connection.
This is all because target device does not have internet...