    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.
DatagramSocket(int, InetAddress)
  Creates a datagram socket, bound to the specified local address.

##

close()
  Close the datagram socket.
getLocalAddress()
  Gets the local address to which the socket is bound.
getLocalPort()
  Returns the local port that this socket is bound to.
getSoTimeout()
  Retrive setting for SO_TIMEOUT.
receive(DatagramPacket)
  Receives datagram packet.
send(DatagramPacket)
  Sends Datagram Packet to the destination address
setSoTimeout(int)
  Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

##

DatagramSocket

      public DatagramSocket() throws SocketException

  Creates a datagram socket

DatagramSocket

      public DatagramSocket(int port) throws SocketException

  Creates a datagram socket. The local port must be between 0 and 65535 inclusive.

  Parameters:
    local - port to use

DatagramSocket

      public DatagramSocket(int port,
                            InetAddress laddr) throws SocketException

  Creates a datagram socket, bound to the specified local address. The local port must be between 0 and 65535 inclusive.

  Parameters:
    port - local port to use
    laddr - local address to bind

##

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
  See Also:
    DatagramPacket

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
  See Also:
    DatagramPacket

getLocalAddress

      public InetAddress getLocalAddress()

  Gets the local address to which the socket is bound.

getLocalPort

      public int getLocalPort()

  Returns the local port that this socket is bound to.

setSoTimeout

      public synchronized void setSoTimeout(int timeout) throws SocketException

  Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a call to receive() for this DatagramSocket will block for only this amount of time. If the timeout expires, a java.io.InterruptedIOException is raised, though the ServerSocket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

getSoTimeout

      public synchronized int getSoTimeout() throws SocketException

  Retrive setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).

close

      public void close()

  Close the datagram socket.

    All Packages  Class Hierarchy  This Package  Previous  Next  Index