Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to send Multiple Files? #3

Open
shahkarraza001 opened this issue Aug 27, 2018 · 10 comments
Open

How to send Multiple Files? #3

shahkarraza001 opened this issue Aug 27, 2018 · 10 comments
Labels

Comments

@shahkarraza001
Copy link

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

@karuppiah7890
Copy link
Member

karuppiah7890 commented Aug 27, 2018 via email

@shahkarraza001
Copy link
Author

shahkarraza001 commented Aug 29, 2018

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

@shahkarraza001
Copy link
Author

can you guide me logically how to send and receive multiple files.?

@karuppiah7890
Copy link
Member

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

@karuppiah7890
Copy link
Member

karuppiah7890 commented Sep 2, 2018

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 😁

@karuppiah7890 karuppiah7890 changed the title Send Multiple Files How to send Multiple Files? Sep 2, 2018
@shahkarraza001
Copy link
Author

shahkarraza001 commented Sep 2, 2018 via email

@karuppiah7890
Copy link
Member

Happy that it was helpful 😄

@shahkarraza001
Copy link
Author

how can i contribute in this project. ? Will you please give me access .

@karuppiah7890
Copy link
Member

karuppiah7890 commented Oct 4, 2018 via email

@shahkarraza001
Copy link
Author

okay.. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants