Reputation: 71
I need a java program to download a series of file from a web server and I need to be able to close and then reopen the tcp/ip connection between each file download.
Not sure how to do this.
Upvotes: 0
Views: 1785
Reputation: 641
use the logic: Please post something that you have tried.
do{
connection.open;
while(!eof){
fetchfiles();
}
connection.close;
}while(no of files yet to download);
Upvotes: 0
Reputation: 319
Here is a low-level way of retrieving any information from not only socket 80 (http) but generically to retrieve mail, do a 'telnet' etc:
socket = new Socket();
socket.connect(new InetSocketAddress(host, port));
reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
now to do a call to retrieve a page, send the get command, set the content-type, and send two '\n'.
There is a higher-level solution: Send HTTP GET request with header
Upvotes: 1
Reputation: 532
You can create a Socket
for the IP and port you want to send it to, then read the file into a byte array using a FileInputStream
and send that byte array through a DataOutPutStream
, then when done just flush the dataOutPutStream and close the Socket and call the function again sending the next file.
Upvotes: 0