Here's my code
Socket s = new Socket();
s.setSoTimeout(5000);
s.connect(url, 5000);
InputStreamReader inputStreamReader = new InputStreamReader(s.getInputStream());
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line;
while ((line = bufferedReader.readLine()) != null){
System.out.println(line);
}
So connect timeout and read timeout are set
but i met a link : http://scfire-mtc-aa01.stream.aol.com:80/stream/1023
My code stucked at this line :
bufferedReader.readLine();
now I check content-type of input stream before calling
bufferedReader.readLine();
to avoid this problem, but I am still wondering why
bufferedReader.readLine();
stuck?
thanks for any help
You're talking to HTTP sites but you aren't sending any HTTP requests. So you don't get any HTTP responses. You are waiting for the response but the server is still waiting for the request.
Don't use Sockets for this, use URLs and URLConnections.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.