General description
In the TCP/IP protocol family, UDP and TCP are also on the transport layer. User datagram is a concept of UDP.
UDP provides a simple and unreliable information transmission service for transactions. It does not provide reliable mechanisms, flow control, and error recovery functions for IP protocols.
UDP is basically an interface between the IP protocol and the upper-layer protocol. From the perspective of user data packaging at different layers, the UDP message format is quite simple:
16
32bit
Source port
Destination port target port
Length (in bytes, including the header and user data area)
Checksum (Checksum)
Data
Due to the checksum, UDP also introduced a pseudo header, which leads to the close relationship between UDP and the IP layer and undermines the layered principle.
Java datagram support
The java.net package provides two types of mongoramsocket and mongorampacket to support datagram communication. Mongoramsocket is used to establish communication connections for transmitting datagram between programs, and mongorampacket is used to represent a datagram.
DatagramSocket indicates the socket for sending and receiving data packets. A datagram socket is the sending and receiving point of the packet delivery service. On a datagram socket, each packet sent and received is independently addressable and routed. Multiple packets sent from one machine to another have different routes in any order of arrival.
For ipvramsocket, UDP broadcast transmission is always enabled (that is the default setting ). to receive broadcast packets, this type of instance should be bound to the general address (wildcard address ). in some implementations, when bound to more specific addresses, the broadcast package can also receive.
For example:
DatagramSocket s = new DatagramSocket (null );
S. bind (new InetSocketAddress (8888 ));
This is equivalent:
DatagramSocket s = new DatagramSocket (8888 );
In both cases, an ingress ramsocket instance that can receive broadcasts on port 8888 is created.
Constructor Summary
DatagramSocket ()
Constructs a datatesocket and binds it to any available port on the local host machine.
Protected
DatagramSocket (DatagramSocketImpl impl)
Creates an unbound datatesocket with the specified ramsocketimpl.
DatagramSocket (int port)
Constructs a datatesocket and binds it to the specified port on the local host machine.
DatagramSocket (int port, InetAddress laddr)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service