I’m experiencing an issue with socket connections on Android 11 and above. When attempting to connect to a wrong host address or port, the socket’s isConnected attribute returns true, whereas on older Android versions, it correctly throws a timeout exception.
try {
Socket socket = new Socket();
socket.connect(new InetSocketAddress(host, port), 10000);
}catch (SocketTimeoutException e) {
// Exception handler
}
How can I make the socket connection behave consistently across all Android versions? or whats alternative way to write my code?