Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - The problem of garbled communication between linux and c socket using java socket
The problem of garbled communication between linux and c socket using java socket

It should be a character set problem.

First of all, you must determine which encoding method is used in the data returned by Linux, such as: GBK.

Correspondingly, on the Java side, the string information is converted into a byte array and written to the Socket, and the read data is also converted into a string,

For example:

String s = "Chinese" ;

sockoutputstream.write (s.getBytes ("GBK")) ;

When read out,

byte [] buf = sockinputStream.read ()

String s = new String (buf, "GBK") ;

That's it.