Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The perfect method of Chinese garbled code in socket

Shulou Source: shulou.com Published: 2022-06-02 06:50:54 10月03日 Update

This article mainly shows you the "excellent method of socket Chinese garbled code". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "excellent method of socket Chinese garbled code".

The solution to Chinese garbled in socket is to use "new OutputStreamWriter (client.getOutputStream ()," UTF-8 "...") to read and write buffers. The code is fine.

Operating environment of this article: windows7 system, DELL G3 computer

What about the Chinese garbled code in socket?

Solution of Chinese garbled code in Socket communication

Use these two lines of code for reading and writing to 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 and the basic operation unit of path communication that supports TCP/IP protocol. The socket can be regarded as the endpoint of double communication between processes between different hosts, which constitutes the programming interface within a single host and between the whole network. Sockets exist in the communication domain, which is an abstract concept introduced to deal with general thread communication through sockets. Sockets usually exchange data with sockets in the same domain (data exchange may also cross domain boundaries, but some interpreter must be executed), and various processes use the same domain to communicate with each other using the Internet protocol suite.

Socket (socket) can be regarded as the endpoint in the respective communication connection when two network applications communicate, which is a logical concept. It is the API (application programming interface) of inter-process communication in the network environment, and it is also a communication endpoint that can be named and addressed. each socket in use has its own type and a connected process. During communication, a piece of information to be transmitted by one of the network applications is written into the Socket of its host, and the Socket sends the information to the Socket of another host through the transmission medium connected to the network interface card (NIC), so that the other party can receive the information. Socket is a combination of IP addresses and ports that provide a mechanism for sending packets to application layer processes.

The above is all the contents of this article entitled "the Best way to garble socket Chinese". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Communications sockets garbled Chinese network processes hosts programs applications excellent methods information content applications data endpoints articles UTF-8 code interfaces Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft OPPO Reno MariaDB vpn