A project that I'm working on needs to pass 3 text files from the Server to the Client.
This what I'm doing
Server side :Wait for client, once connected to client pick up the files and transmit it to the client one after another.
Client side :Connect to server and accept the files one after an other.
I'm only able to receive the first txt file after which I'm getting an ArrayIndexOutOfBoundsException.
In debug mode I noticed that no data is being read on the second read segment on the client side.
Here is a segment of the server side code:
This is the client side code :
Any help on how to synchronize the file sending so the client reads all three files is much appreciated
"A single conversation with a wise man is better than ten years of study."
I don't see in your code how the receiver is supposed to tell where one file ends and the next one starts. It has this mysterious "filesize" variable which I don't see where that comes from or what it's set to. Do you only ever plan to send files of that size and no other size?
Joined: Mar 02, 2009
That is the problem I'm having, I don't know how to inform the receiver that the first file has ended and the second has started.
How can put such a system of notification into place?
Also I don't plan to fix the size of the files as all three files are of different sizes
Your protocol needs to be redesigned so it knows when a new portion is read. An example of what could be sent:
- an int indicating the name's length when converted to byte using a fixed charset (e.g. UTF-8)
- the file name as a byte using that charset
- an int indicating the file size
- the file in bytes.