API Overview API Index Package Overview Direct link to this page
JDK 1.6
  java.net. DatagramSocket View Source
Author(s)
Pavani Diwanji
Since
JDK1.0
Version
1.101, 06/08/06
Serial
Hierarchy
 Object
      DatagramSocket
Implements
Subclasses
Description
public class DatagramSocket
  This class represents a socket for sending and receiving datagram packets.
Constructors
public DatagramSocket () throws SocketException
  Constructs a datagram socket and binds it to any available port on the local host machine.
protected DatagramSocket (DatagramSocketImpl impl)
  Creates an unbound datagram socket with the specified DatagramSocketImpl.
public DatagramSocket (int port) throws SocketException
  Constructs a datagram socket and binds it to the specified port on the local host machine.
public DatagramSocket (int port, InetAddress laddr) throws SocketException
  Creates a datagram socket, bound to the specified local address.
public DatagramSocket (SocketAddress bindaddr) throws SocketException
  Creates a datagram socket, bound to the specified local socket address.
Methods
Hide/Show inherited methods
publicsynchronized void bind (SocketAddress addr) throws SocketException
  Binds this DatagramSocket to a specific address & port.
public void close ()
  Closes this datagram socket.
public void connect (InetAddress address, int port)
  Connects the socket to a remote address for this socket.
public void connect (SocketAddress addr) throws SocketException
  Connects this socket to a remote socket address (IP address + port number).
pack-private void createImpl () throws SocketException
public void disconnect ()
  Disconnects the socket.
publicsynchronized boolean getBroadcast () throws SocketException
  Tests if SO_BROADCAST is enabled.
public DatagramChannel getChannel ()
  Returns the unique DatagramChannel object associated with this datagram socket, if any.
pack-private DatagramSocketImpl getImpl () throws SocketException
  Get the DatagramSocketImpl attached to this socket, creating it if necessary.
public InetAddress getInetAddress ()
  Returns the address to which this socket is connected.
public InetAddress getLocalAddress ()
  Gets the local address to which the socket is bound.
public int getLocalPort ()
  Returns the port number on the local host to which this socket is bound.
public SocketAddress getLocalSocketAddress ()
  Returns the address of the endpoint this socket is bound to, or null if it is not bound yet.
public int getPort ()
  Returns the port for this socket.
publicsynchronized int getReceiveBufferSize () throws SocketException
  Get value of the SO_RCVBUF option for this DatagramSocket, that is the buffer size used by the platform for input on this DatagramSocket.
public SocketAddress getRemoteSocketAddress ()
  Returns the address of the endpoint this socket is connected to, or null if it is unconnected.
publicsynchronized boolean getReuseAddress () throws SocketException
  Tests if SO_REUSEADDR is enabled.
publicsynchronized int getSendBufferSize () throws SocketException
  Get value of the SO_SNDBUF option for this DatagramSocket, that is the buffer size used by the platform for output on this DatagramSocket.
publicsynchronized int getSoTimeout () throws SocketException
  Retrieve setting for SO_TIMEOUT.
publicsynchronized int getTrafficClass () throws SocketException
  Gets traffic class or type-of-service in the IP datagram header for packets sent from this DatagramSocket.
public boolean isBound ()
  Returns the binding state of the socket.
public boolean isClosed ()
  Returns whether the socket is closed or not.
public boolean isConnected ()
  Returns the connection state of the socket.
publicsynchronized void receive (DatagramPacket p) throws IOException
  Receives a datagram packet from this socket.
public void send (DatagramPacket p) throws IOException
  Sends a datagram packet from this socket.
publicsynchronized void setBroadcast (boolean on) throws SocketException
  Enable/disable SO_BROADCAST.
publicstaticsynchronized void setDatagramSocketImplFactory (DatagramSocketImplFactory fac) throws IOException
  Sets the datagram socket implementation factory for the application.
publicsynchronized void setReceiveBufferSize (int size) throws SocketException
  Sets the SO_RCVBUF option to the specified value for this DatagramSocket.
publicsynchronized void setReuseAddress (boolean on) throws SocketException
  Enable/disable the SO_REUSEADDR socket option.
publicsynchronized void setSendBufferSize (int size) throws SocketException
  Sets the SO_SNDBUF option to the specified value for this DatagramSocket.
publicsynchronized void setSoTimeout (int timeout) throws SocketException
  Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
publicsynchronized void setTrafficClass (int tc) throws SocketException
  Sets traffic class or type-of-service octet in the IP datagram header for datagrams sent from this DatagramSocket.
Fields
Hide/Show inherited fields
pack-private InetAddress connectedAddress
pack-private int connectedPort
pack-private int connectState
pack-privatestatic DatagramSocketImplFactory factory
The factory for all datagram sockets.
pack-private DatagramSocketImpl impl
pack-privatestatic Class implClass
pack-private boolean oldImpl
Are we using an older DatagramSocketImpl?
pack-privatefinalstatic int ST_CONNECTED = "1"
pack-privatefinalstatic int ST_CONNECTED_NO_IMPL = "2"
pack-privatefinalstatic int ST_NOT_CONNECTED = "0"
Nested Classes
Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar