Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Downloading multiple files  RSS feed

 
Kin Ng
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Is it possible to download multiple files(on the same host) through one socket connection?
or do we have to make a new socket connection for each GET request.

Regards,


Kin
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you writing both the client & server? You should be able to make them have a conversation of any number of messages. My
CommandServer experiment does extended conversations, and may serve as an example. But it only deals in lines, not binary files. With files it may be harder to know when a message is complete. A header with the file size might help.

PS I'll make excuses about that code - it was early in my Java days and I did not grok threads and streams all that well. There may be much room for improvement.
 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible if you provide some sort of data - tagging mechanism. Different download sessions will be tagged with a unique tag id and the downloader side will de-encapsulate the tag id and append the data block to a physical file.

It dun seems feasible as it required much programming complexity. Why not have one download session be one socket? After all the ServerSocket class will spawn a Socket for every connection stream that connects to it? The same client can have more than one Socket connection to the ServerSocket instance.

Regards,
Clivant
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!