0% found this document useful (0 votes)
76 views2 pages

Datagrampacket: Java Datagramsocket Class Represents A Connection-Less Socket For Sending and

The DatagramSocket class represents a connectionless socket that sends and receives datagram packets over a network. DatagramPacket is a data container that can be sent or received, but there is no guarantee of packet delivery or order. Commonly, DatagramSocket is constructed without parameters to bind to an available port on localhost, or with a specific port number and/or InetAddress. DatagramPacket is commonly constructed with a byte array and length to receive packets, or with a byte array, length, destination InetAddress and port to send packets.

Uploaded by

Manar Abdo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views2 pages

Datagrampacket: Java Datagramsocket Class Represents A Connection-Less Socket For Sending and

The DatagramSocket class represents a connectionless socket that sends and receives datagram packets over a network. DatagramPacket is a data container that can be sent or received, but there is no guarantee of packet delivery or order. Commonly, DatagramSocket is constructed without parameters to bind to an available port on localhost, or with a specific port number and/or InetAddress. DatagramPacket is commonly constructed with a byte array and length to receive packets, or with a byte array, length, destination InetAddress and port to send packets.

Uploaded by

Manar Abdo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

2-Summarize the methods of DatagramSocket and DatagramPacket classes.

Java DatagramSocket class represents a connection-less socket for sending and


receiving datagram packets. It is a mechanism used for transmitting datagram
packets over network.`

A datagram is basically an information but there is no guarantee of its content,


arrival or arrival time.

Commonly used Constructors of DatagramSocket class

o DatagramSocket() throws SocketEeption: it creates a datagram socket and


binds it with the available Port Number on the localhost machine.
o DatagramSocket(int port) throws SocketEeption: it creates a datagram
socket and binds it with the given Port Number.
o DatagramSocket(int port, InetAddress address) throws SocketEeption: it
creates a datagram socket and binds it with the specified port number and host
address.

Java DatagramPacket is a message that can be sent or received. It is a data


container. If you send multiple packet, it may arrive in any order. Additionally,
packet delivery is not guaranteed.

Commonly used Constructors of DatagramPacket class

o DatagramPacket(byte[] barr, int length): it creates a datagram packet. This


constructor is used to receive the packets.
o DatagramPacket(byte[] barr, int length, InetAddress address, int
port): it creates a datagram packet. This constructor is used to send the
packets.

3-what is the Socket?

Sockets allow communication between two different processes on the same or


different machines. To be more precise, it's a way to talk to other computers using
standard Unix file descriptors. In Unix, every I/O action is done by writing or
reading a file descriptor. A file descriptor is just an integer associated with an open
file and it can be a network connection, a text file, a terminal, or something else.

To a programmer, a socket looks and behaves much like a low-level file descriptor.
This is because commands such as read() and write() work with sockets in the same
way they do with files and pipes.

4-what InetAddress is Used for?

The java.net.InetAddress class provides methods to get the IP address of any


hostname. An IP address is represented by 32-bit or 128-bit unsigned number.
InetAddress can handle both IPv4 and IPv6 addresses.

You might also like