Measured:
Socket socket = new socket (IP, internetconfig.mornitorport);
Send a message to the server
PrintWriter out = new PrintWriter (new BufferedWriter (New OutputStreamWriter (Socket.getoutputstream (), Internetsendthread.stream_decode_mode)), true);
OUT.PRINTLN (msg);
System.out.println (tag+ "end writer to IP =" +ip);
Get the return message from the server
BufferedReader readbuffer = new BufferedReader (New InputStreamReader (Socket.getinputstream (), Internetsendthread.stream_decode_mode));
res = Readbuffer.readline ();
Reference:
Method One:
Mainly the problem of server side and client coding matching
No matter what code you use
As long as the ends match
Just OK.
Do not assume that the default encoding
Try each.
Rather a line of code
Key code
public static final String bm= "GBK"; Globally defined to accommodate other parts of the system
InputStream is;
BufferedReader BR;
BW = new BufferedWriter (new OutputStreamWriter (OS,BM));
br = new BufferedReader (new InputStreamReader (IS,BM));
Bw.write (msg);
msg= new String (B,BM);
OutputStream OS = Socket.getoutputstream ();
Os.write (Str.getbytes (BM));
The code-related sections throughout the project are shown above
The effect is as follows
Method Two:
1. Server-side output:
PrintWriter out = new PrintWriter (new BufferedWriter (New OutputStreamWriter (Socket.getoutputstream (), "Utf-8"), true) ;
2. When the client receives:
BufferedReader in = new BufferedReader (New InputStreamReader (Client.getinputstream (), "UTF-8"));
String read = In.readline ();
Android Socket Communication