Joke Collection Website - Blessing messages - What is the difference between TCP and UDP communication, and how to realize it in java respectively?

What is the difference between TCP and UDP communication, and how to realize it in java respectively?

TCP is connection-oriented, UDP is non-connection-oriented, and does not copy data. Simply put here: \x0d\TCP needs the legendary three-way handshake when establishing a connection, and the server and the client only need to confirm each other's identities. After the connection is established, they will start transmitting messages until one party disconnects. It's like two people talking on the phone, and they can't talk until they get through. \x0d\UDP only sends datagrams. Its advantage is that it is fast and not as troublesome as TCP. It is only responsible for sending information, and does not guarantee the accuracy and completeness of the information, just like sending text messages. The text message is out, but it doesn't matter if there is any problem in the middle and whether the other party's mobile phone can receive it. \x0d\ In order to realize the communication of the above two protocols in java, socket can be used to establish a connection. Socket can be understood as dock, but it is actually a socket. Here, in simple terms, it is like two cities transporting goods through the dock. As for how to establish two connections through socket, there are a lot of online materials, so I won't copy the examples here.