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.

Constructor Index

 o DatagramSocket()
Creates a datagram socket
 o DatagramSocket(int)
Creates a datagram socket

Method Index

 o close()
Close the datagram socket.
 o finalize()
Code to perform when this object is garbage collected.
 o getLocalPort()
Returns the local port that this socket is bound to.
 o receive(DatagramPacket)
Receives datagram packet.
 o send(DatagramPacket)
Sends Datagram Packet to the destination address

Constructors

 o DatagramSocket
  public DatagramSocket() throws SocketException
Creates a datagram socket
 o DatagramSocket
  public DatagramSocket(int port) throws SocketException
Creates a datagram socket
Parameters:
local - port to use

Methods

 o 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
 o 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
 o getLocalPort
  public int getLocalPort()
Returns the local port that this socket is bound to.
 o close
  public synchronized void close()
Close the datagram socket.
 o 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