下面的代码在 AsynTask 和 try-catch 中实现。如果服务器在指定时间内没有响应,我想中断 bufferreader.readline()。我怎样才能做到这一点?
Socket tcpSocket = new Socket();
tcpSocket.connect(new InetSocketAddress("mydomain.com", 5000),
SOCK_TIMEOUT);
InputStream inputStream = tcpSocket.getInputStream();
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(inputStream));
String jsonData = bufferReader.readLine(); //blocks here