java.net.DatagramPacket
This class represents a datagram packet.
Datagram packets are used to implement a connectionless packet delivery service. Each message is routed from one machine to another based solely on information contained within that packet. Multiple packets sent from one machine to another might be routed differently and might arrive in any order. Packet delivery is not guaranteed.
Unless otherwise specified, passing a null argument causes a NullPointerException to be thrown.
Some methods of DatagramPacket class
DatagramPacket(byte[], int): This method constructs a DatagramPacket for receiving packets of length.
DatagramPacket(byte[], int, int): This method constructs a DatagramPacket for receiving length packets, specifying an offset into the buffer.
DatagramPacket(byte[], int, SocketAddress): This method constructs a datagram packet for sending packets of length to the specified port number on the specified host
DatagramPacket(byte[], int, InetAddress, int): This method constructs a datagram packet for sending packets of length to the specified port number on the specified host.
DatagramPacket(byte[], int, int, SocketAddress): This method constructs a datagram packet for sending packets of length with offset to the specified port number on the specified host.
DatagramPacket(byte[], int, int, InetAddress, int): This method constructs a datagram packet for sending length packets with offset to the specified port number on the specified host.
getAddress(): This method returns the IP address of the machine to which this datagram is being sent or from which the datagram was received, or null if not set.
getData(): This method returns the data buffer.
getLength(): This method returns the length of the data to be sent or the length of the data received.
getOffset(): This method returns the offset of the data to be sent or the offset of the data received.
getPort(): This method returns the port number on the remote host to which this datagram is being sent or from which the datagram was received, or 0 if not set.
getSocketAddress(): This method returns the SocketAddress (usually IP address + port number) of the remote host that this packet is being sent to or is coming from.
setAddress(InetAddress): This method sets the IP address of the machine to which this datagram is being sent.
setData(byte[]): This method sets the data buffer for this packet. With the offset of this DatagramPacket set to 0, and the length set to the length of buf.
setData(byte[], int, int): This method sets the data buffer for this packet. This sets the data, length, and offset of the packet.
setLength(int): This method sets the length for this packet. The length of the packet is the number of bytes from the packet's data buffer that will be sent or the number of bytes of the packet's data buffer that will be used for receiving data.
setPort(int): This method sets the port number on the remote host to which this datagram is being sent.
setSocketAddress(SocketAddress): This method sets the SocketAddress (usually IP address + port number) of the remote host to which this datagram is being sent.
Some other classes/interfaces of java.net
Authenticator: The class Authenticator represents an object that knows how to obtain authentication for a network connection.
BindException: Signals that an error occurred while attempting to bind a socket to a local address and port.
CacheRequest: Represents channels for storing resources in the ResponseCache.
CacheResponse: Represent channels for retrieving resources from the ResponseCache.
ConnectException: Signals that an error occurred while attempting to connect a socket to a remote address and port.
ContentHandler: The abstract class ContentHandler is the superclass of all classes that read an Object from a URLConnection.
ContentHandlerFactory: This interface defines a factory for content handlers. Implementing this interface should map a MIME type into an instance of ContentHandler.
CookieHandler: A CookieHandler object provides a callback mechanism to hook up an HTTP state management policy implementation into the HTTP protocol handler.
CookieManager: CookieManager provides a concrete implementation of CookieHandler, which separates the storage of cookies from the policy surrounding accepting and rejecting cookies.
CookiePolicy: CookiePolicy implementations decide which cookies should be accepted and which should be rejected.
CookieStore: A CookieStore object represents storage for cookies. Can store and retrieve cookies.
DatagramPacket: This class represents a datagram packet.
No comments:
Post a Comment