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

Method Index

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

Constructors

 o DatagramSocket
  public DatagramSocket() throws SocketException
Creates a datagram socket

 o 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
 o 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

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
See Also:
DatagramPacket
 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
See Also:
DatagramPacket
 o getLocalAddress
  public InetAddress getLocalAddress()
Gets the local address to which the socket is bound.

 o getLocalPort
  public int getLocalPort()
Returns the local port that this socket is bound to.

 o 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.

 o 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).

 o close
  public void close()
Close the datagram socket.


All Packages  Class Hierarchy  This Package  Previous  Next  Index