Java socket programming example based on TCP protocol
This paper describes the socket programming method of Java based on TCP protocol, which is shared for your reference. The specific analysis is as follows:
The following is a one-to-one communication programming implementation. We will continue to learn the implementation of one server listening to multiple clients.
The main steps used here are as follows:
Step 1: select a specific port (e.g. 4800) create a new socket object. Step 2: construct a BufferedReader object with the system input device, which is used to receive the characters input by the system keyboard. Step 3: construct a printwriter with the output stream obtained from the socket object. Step 4: construct a corresponding BufferedReader object with the input stream obtained from the socket object, which is used to receive the information sent by the server
I understand that the socket is closed: the socket is opened first and then closed, and the socket is closed finally.
The following is the code implementation of the client: