I have a problem realizing a C client/Java server. I have a problem with the put method in server side. My problem is the same as (Handling C char arrays with Java char arrays) but the given solution doesn't work in my case.
My problem is that I receive a corrupt file.
When I see the raw of the original file and the received file i noticed that Java doesn't recognize some character. For example in the original file I have the character represented by 89 in the received file I have 'ef bf bd' if I write the byte array in UTF-8 or '3f' if I write it in US-ASCII encoding. Here's the important part of my program :
InputStream entreeSocket = socketService.getInputStream();
FileOutputStream out = new FileOutputStream(filename);
while(length > 0){
int nb;
if(length > buffer.length)
nb = socket.read(buffer,0,buffer.length);
else
nb = socket.read(buffer,0,length);
out.write(buffer,0,nb);
if(nb == -1) break;
length -=nb;
}
out.close();
socket.close();
Client side :
char buffer[1024];
while(length > 0 ){
nb = read(fd,buffer,1024);
write(sockfd,buffer,nbChar);
length = length - nb;;
}
Any help would be appreciated. Thanks in advance.