Detailed explanation of java socket UDP instance

UDP programming example

Server side:

client:

explain:

1. Strictly speaking, UDP is not divided into server and client. Unlike ServerSocket and socket in TCP, there is only datagram socket in UDP.

2. UDP and TCP ports are separated. For example, UDP has a port with port number 5678, and TCP also has a port with port number 5678.

3. UDP is connectionless, so specify the IP: port to send in the sent data package.

4. If you want to send long, int and other types of data, you need to use bytearrayoutputstream, dataoutputstream, bytearrayinputstream and bytearrayinputstream, as follows:

Server side:

client:

Thank you for reading, hope to help you, thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>