C side:
unsigned char myBuffer[62];
fread(myBuffer,sizeof(char),62,myFile);
send(mySocket, myBuffer, 62,0);
JAVA side:
bufferedReader.read(tempBuffer,0,62);
Now in JAVA program i receive (using socket) values less than 0x80 in C program with no problems, but i receive 0xFD value for all values equal or greater than 0x80 in C program.
I need perfect solution for this problem.
Don't use a
Readerto read bytes, use anInputStream!A
Readeris meant to read characters; it receives a stream of bytes and (tries and) converts these bytes to characters; you lose the original bytes.In more details, a
Readerwill use aCharsetDecoder; this decoder is configured so that unknown byte sequences are replaced; and the encoding used here likely replaces unknown byte sequences with character 0x00fd, hence your result.Also, you don't care about signed vs unsigned;
1000 0000may be 128 as anunsigned charin C and -127 as abytein Java, it still remains1000 0000.If what you send is really text, then it means the charset you have chosen for decoding is not the good one; you must know the encoding in which the files on your original system are written.