1. Datagram Socket class
The Datagramsocket class, the socket used to send and receive datagram packets.
Datagramsocket Construction Method
Structuring method formats |
Description |
Public Datagramsocket() |
Constructs a datagram socket, binds to any locally determined available port |
Public datagramsocket(int port) |
Socket bound to the specified port |
Public datagramsocket(int port, inetaddress laddr) |
Binds to the specified port, the specified address |
1.1. Send data
Send datagram packet data using the Send method of the Datagramsocket class.
1.1. Create a Send Socket object
You can use the constructor directly to generate it.
1.2. Create data and package
Java provides a class called the "datagram Packet" class that uses the class new object, which is the datagram packet we are sending.
1.3. Send data
1.4. Releasing Resources
1.2. Receiving data
Receive datagram packet data using the Receive method of the Datagramsocket class.
1.2.1. Create a Receive socket object 1.2.2. Receive data 1.2.3. Parse data 1.2.4. Output data 1.2.5. Releasing resources 2. Datagram Packet class
This class, which means "datagram packets", is used to implement a no-connection packet delivery service.
Datagrampacket Construction Method
Transceiver |
Structuring method formats |
Parameters |
Description |
Send |
Public Datagrampacket (byte[] buf, int len, inetaddress add, int port) |
BUF, send out the data |
Construct object used to send packets to the specified address, port |
Receive |
Public Datagrampacket (byte[] buf, int len) |
BUF, save the received content |
Constructs an object that receives Len-length data |
JAVA-API Datagramsocket Datagram Socket class