I am writing a simple client/server application to download/ upload files from/to server. I am using my own protocol. The problem is that when I am trying to send a binary files (an image for example) it doesn't work. I am using the following code:
I receive a file at the other end, with the same size but the first 10 offsets are different( I checked that using the windows command cmp). Can any body help me with that ?
First, Available Doesnt Do What You Think It Does Second, what types are headerWriter and userDataWriter? Using Writers for binary data is a bad idea. Writers do character conversion on data and if the values in the data can't be converted into the current charset you will lose some of that particular value.
headerReader is of type BufferedReader and userDataReader is of type DataOutputStream. so pleaaaaaaaase what should I use in order for this to work. this problem has been haunting me for a long long time. I read the link you gave me and I replaced my code with the following, but still it doesn't work:
Originally posted by aymane chetibi: I have added this condition that the bytesRead are less that 1024, than we have to finish looping, because before it stayed blocked somewhere even if it's finished. [/QB]
Keep in mind that the number of bytes can be less than the size of the array for several reasons, not just EOF. Network congestion for one. I would expect that you would get a Exception when you try to read after the server has invoked socketFromClient.close(). Are you writing exceptions out? In any case, the most reliable way to move a file using a custom protocol that I've found is to send the file size, then read that many bytes. As for different behavior on client and server, are you sure you are keeping the classes in sync? Exactly what is the problem? You said the "first ten offsets are different". What do you mean by that? Is it only the first ten, or is that all you've checked?