Class java.net.DatagramSocket
All Packages Class Hierarchy This Package Previous Next Index
Class java.net.DatagramSocket
java.lang.Object
|
+----java.net.DatagramSocket
- public class DatagramSocket
- extends Object
The datagram socket class implements unreliable datagrams.
- DatagramSocket()
- Creates a datagram socket
- DatagramSocket(int)
- Creates a datagram socket
- close()
- Close the datagram socket.
- finalize()
- Code to perform when this object is garbage collected.
- getLocalPort()
- Returns the local port that this socket is bound to.
- receive(DatagramPacket)
- Receives datagram packet.
- send(DatagramPacket)
- Sends Datagram Packet to the destination address
DatagramSocket
public DatagramSocket() throws SocketException
- Creates a datagram socket
DatagramSocket
public DatagramSocket(int port) throws SocketException
- Creates a datagram socket
- Parameters:
- local - port to use
send
public void send(DatagramPacket p) throws IOException
- Sends Datagram Packet to the destination address
- Parameters:
- DatagramPacket - to be sent. The packet contains the buffer of bytes, length and destination InetAddress and port.
- Throws: IOException
- i/o error occurred
receive
public synchronized void receive(DatagramPacket p) throws IOException
- Receives datagram packet.
- Parameters:
- DatagramPacket - to be received.
On return, the DatagramPacket contains the buffer in which the data is received, packet length, sender's address and sender's port number. Blocks until some input is available.
- Throws: IOException
- i/o error occurred
getLocalPort
public int getLocalPort()
- Returns the local port that this socket is bound to.
close
public synchronized void close()
- Close the datagram socket.
finalize
protected synchronized void finalize()
- Code to perform when this object is garbage collected.
- Overrides:
- finalize in class Object
All Packages Class Hierarchy This Package Previous Next Index