How to send Multiple Files?
I want to send multiple files using FileShare project. Right now i am able to send single file. But When I select multiple files to send, it only sends first selected file and then closes the connection. Can you guide me please how to implement that
Hey :)
Thanks for checking out the project. Currently I am not maintaining this project though. You can read the code and understand more though :) sending multiple files shouldn't be very tough
i have implemented the code to send multiple files on the sender side i have send the arraylist containing list of path of files InetAddress receiverIP = getReceiverIP(); i = new Intent(context,SenderService.class); i.putExtra(RECEIVER_IP,receiverIP); i.putExtra(PORT,port); i.putExtra(MESSENGER,new Messenger(mHandler)); i.putStringArrayListExtra(FILES,files); context.startService(i);
sender thread `for (int i=0;i<filesToSend.size();i++){
DataOutputStream out = new DataOutputStream(senderSocket.getOutputStream());
message = Message.obtain();
message.what = FileSender.SENDING_FILE;
message.obj = "";
messenger.send(message);
fileToSend= new File(filesToSend.get(i));
// Send File Name
Log.i("file name",""+fileToSend.getName());
out.writeUTF(fileToSend.getName());
DataInputStream din = new DataInputStream(new FileInputStream(fileToSend));
// Send File Size
long fileSize = fileToSend.length();
Log.i("file Size",""+fileToSend.length());
out.writeLong(fileSize);
int totalLength = 0;
int length = 0;
byte[] sendData = new byte[PKT_SIZE];
long startTime = System.currentTimeMillis();
// Send the file data
while ((length = din.read(sendData)) != -1) {
Log.i("Length",""+length);
out.write(sendData, 0, length);
totalLength += length;
}
long stopTime = System.currentTimeMillis();
din.close();
double time = (stopTime - startTime) / 1000.0;
double speed = (totalLength / time) / 1048576.0;
Log.i("Total time"," "+time +": Speed :"+speed );
}`
but in receiver side after receiving first file it closes the socket. can you guide me please how to implement this on receiver side
can you guide me logically how to send and receive multiple files.?
I haven't thought much about sending multiple files. I am sorry, but like I said, I don't have much time to spend on this project, for now. I don't even remember how I implemented this. And I need to spend some time reading the code for both sender and receiver.
But in an abstract way, I can tell this about receiving multiple files - you could think about a similar logic that you have done here, like using a loop and getting files. To start with, first send to the receiver the number of files you are gonna send, so that the receiver knows how many to expect and when to stop, similar to how we are currently file name, file size and then the file content, before all that, first send the number of files, it can be one, it can be two. I "think" currently your receiver does not have for loop, if it did, it would need the count for how many times to run the loop, or if there's no count, some sort of condition to break out of the loop. But I think sending the number of files that are gonna be sent could be a good start and it will also be helpful for the receiver to know if it received all the files, if it didn't, it will be easy to detect an error to tell that some files that were "expected" to be received were not received. I hope this helps 😄 @shahkarraza001
And if you find this project useful, please do contribute to it with features that you are building, if you think it will benefit others 😄 looks like sending multiple files is cool 😁
Thank you so much for your review and suggestions. I have already implemented the code to send multiple files. And i implemented the same technique. While sending the files , number of files are also sent to tell the receiver side. And receiver has to run the loop till numbers of files condition is break. And with that i had to change one statement., After receiving every single file, instead of closing bufferstream. I used bin.flush(), because bufferstream.close() also closes the connection as far as i know.
Get Outlook for Androidhttps://aka.ms/ghei36
From: Karuppiah [email protected] Sent: Sunday, September 2, 2018 9:03:08 AM To: Android-File-Share/FileShare Cc: shahkarraza001; Mention Subject: Re: [Android-File-Share/FileShare] Send Multiple Files (#3)
And if you find this project useful, please do contribute to it if you think it will benefit others 😄
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAndroid-File-Share%2FFileShare%2Fissues%2F3%23issuecomment-417903462&data=02%7C01%7C%7C12e564adb54945b54cb008d61088fe90%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636714577902504647&sdata=V%2BPjG8T8bCJbmMKK7Bt2KN0%2FtFo2n9AhGio6ayLxVGE%3D&reserved=0, or mute the threadhttps://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAks9DRovtD3i_4pfzBhR9PG_Hn_hLknZks5uW1h8gaJpZM4WNOFJ&data=02%7C01%7C%7C12e564adb54945b54cb008d61088fe90%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636714577902504647&sdata=uWXzkwSQd1egSPP3gVGi5QyW%2BYrJgNPINMKWLplAtWU%3D&reserved=0.
Happy that it was helpful 😄
how can i contribute in this project. ? Will you please give me access .
You can fork and raise a PR :) If you want to maintain this repo, then we can discuss about access
On Thu, Oct 4, 2018, 12:09 PM shahkarraza001 [email protected] wrote:
how can i contribute in this project. ? Will you please give me access .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Android-File-Share/FileShare/issues/3#issuecomment-426902346, or mute the thread https://github.com/notifications/unsubscribe-auth/AMNw6B0EUjENiYSzeSv1LzzKDw-T0RuLks5uha0bgaJpZM4WNOFJ .
okay.. 👍