• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

HTTP Range request  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to download in parallel the parts of file. I read that some articles say that. I can use HTTP/1.1 to specify the range i want for each part downloaded at each tcp connection, so I wonder if the following codes can help me to establish a connection while specifying the range. Notice when I excute the codes below nothngi change to the ouput. it seems the following part "Range: bytes=0-500\r\n" doesn't change anything.

Any Help I will I appreciate.


URL url = null;

url = new URL("http://twitter.com/statuses/user_timeline/13507732.atom");





try {

Socket socket = new Socket(url.getHost(), 80);
OutputStream os = socket.getOutputStream();
PrintWriter out = new PrintWriter(os);


String query = url.getQuery();
query = (query == null) ? "" : '?' + query;
String hostname = url.getHost();

// send an HTTP request to the web server
out.write("GET " + url.getPath() + query + " HTTP/1.1\r\n" + // The request
"Host: " + hostname + "\r\n" + // Required in HTTP 1.1
"Range: bytes=0-500\r\n" + // The request
"Connection: close\r\n");
out.println();
out.flush();




// read the response
InputStream inputStream =
socket.getInputStream();
InputStreamReader inputStreamReader =
new InputStreamReader(inputStream);
BufferedReader in =
new BufferedReader(inputStreamReader);


String line;



while ((line = in.readLine()) != null) {



System.out.println(line);



}
// Close everything
out.close();
in.close();
socket.close();


} catch (IOException e) {

System.err.println("Problems talking to " +"twitter user" );
e.printStackTrace();
}
}

}
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the HTTP server process that handles this request understand and implement the "Range" header?
 
kabera james
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so because if what I am saying is true there is no Accept-Range in HTTP header response. Otherwise does this way work only with the server which accept this request

Her is the output for the header


HTTP/1.1 200 OK
Date: Sun, 22 May 2011 11:41:59 GMT
Server: hi
Status: 200 OK
X-Transaction: 1306064519-59527-25959
X-RateLimit-Limit: 150
ETag: "7daf3763c3cc9a1614c71239665257b2"
X-Frame-Options: SAMEORIGIN
Last-Modified: Sun, 22 May 2011 11:41:59 GMT
X-RateLimit-Remaining: 145
X-Runtime: 0.01697
X-Transaction-Mask: a6183ffa5f8ca943ff1b53b5644ef114ff1c24b4
Content-Type: application/atom+xml; charset=utf-8
Content-Length: 18641
Pragma: no-cache
X-RateLimit-Class: api
X-Revision: DEV
Expires: Tue, 31 Mar 1981 05:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
X-MID: 1ac2fd5bee31c1aef41d6a036052d85cec5ea10f
X-RateLimit-Reset: 1306066301
Set-Cookie: k=91.180.130.76.1306064519651327; path=/; expires=Sun, 29-May-11 11:41:59 GMT; domain=.twitter.com
Set-Cookie: guest_id=13060645196569518; path=/; expires=Tue, 21 Jun 2011 11:41:59 GMT
Set-Cookie: _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCOkBgxcwAToHaWQiJWU4MGEyZDFiOTRiY2Y2%250AYzQ3YjVmNDBjYjYzMWU5OWZlIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVy%250AOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--f5f8c641772b04aa6d210abc34e6fb53b93954e6; domain=.twitter.com; path=/; HttpOnly
Vary: Accept-Encoding
X-XSS-Protection: 1; mode=block
Connection: close
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd use an HTTP library (like Apache Commons HttpClient) instead of trying to get all the details right using a Socket.
 
kabera james
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do like to use this so. but I do think is the subclass of URLconnection which is forbidden for our project. Any other suggestions please
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a certain class is forbidden for a project? What kind of requirement is that? Is this a school project that aims to teach you how to implement HTTP?
 
kabera james
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes is the school project . maybe because we will know many things on HTTP header with this
 
Ulf Dittmer
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I'd start by reading the HTTP specification chapter on ranges.
 
kabera james
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the codes work for the server with no restrictions of range request. now i have to look what to do for the server with it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!