Home >Common Problem >What to do if the Chinese socket is garbled?
The solution to the Chinese garbled socket is to use the "new OutputStreamWriter(client.getOutputStream(),"UTF-8"..." code to read and write the buffer.
The operating environment of this article: windows7 system, DELL G3 computer
What should I do if the Chinese socket is garbled?
Socket communication Chinese garbled code solution
Use these two codes to read and write the buffer:
PrintWriter out=new PrintWriter(new OutputStreamWriter(client.getOutputStream(),"UTF-8"),true); BufferedReader msg=new BufferedReader(new InputStreamReader(client.getInputStream(),"UTF-8"));
Related introduction:
Socket (Socket) is the cornerstone of communication , is the basic operating unit that supports road communication of the TCP/IP protocol. Sockets can be regarded as endpoints for dual communication between processes between different hosts. It constitutes the programming interface within a single host and across the entire network. Socket Words exist in the communication domain, which is an abstract concept introduced to handle general thread communication through sockets. Sockets usually exchange data with sockets in the same domain (data exchange may also cross domains boundaries, but at this time some kind of interpreter must be executed), and various processes use this same domain to communicate with each other using the Internet protocol cluster.
Socket (socket) can be regarded as When two network applications communicate, each endpoint in the communication connection is a logical concept. It is an API (Application Programming Interface) for inter-process communication in a network environment, and it is also a communication that can be named and addressed. Endpoint, each socket in use has its type and a process connected to it. During communication, one of the network applications writes a piece of information to be transmitted into the Socket of the host where it is located, and the Socket communicates with the network interface card ( The transmission medium connected to the NIC) sends this information to the Socket of another host so that the other party can receive this information. Socket is a combination of IP address and port, which provides a mechanism for transmitting data packets to the application layer process.
For more related knowledge, please visit the FAQ column!
The above is the detailed content of What to do if the Chinese socket is garbled?. For more information, please follow other related articles on the PHP Chinese website!