JAVA-API Datagramsocket Datagram Socket class

Source: Internet
Author: User

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

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.