<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!--NewPage-->
<html>
<head>
<!-- Generated by javadoc on Wed Jul 28 01:21:15 GMT 1999 -->
<title>
  Class java.net.DatagramSocket
</title>
</head>
<body>
<a name="_top_"></a>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.net.html">This Package</a>  <a href="java.net.DatagramPacket.html#_top_">Previous</a>  <a href="java.net.DatagramSocketImpl.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
<hr>
<h1>
  Class java.net.DatagramSocket
</h1>
<pre>
<a href="java.lang.Object.html#_top_">java.lang.Object</a>
   |
   +----java.net.DatagramSocket
</pre>
<hr>
<dl>
  <dt> public class <b>DatagramSocket</b>
  <dt> extends <a href="java.lang.Object.html#_top_">Object</a>
</dl>
This class represents a socket for sending and receiving datagram packets.
 <p>
 A datagram socket is the sending or receiving point for a 
 connectionless packet delivery service. Each packet sent or 
 received on a datagram socket is individually addressed and 
 routed. Multiple packets sent from one machine to another may be 
 routed differently, and may arrive in any order.
<p>
<dl>
    <dt> <b>See Also:</b>
    <dd> <a href="java.net.DatagramPacket.html#_top_">DatagramPacket</a>
</dl>
<hr>
<a name="index"></a>
<h2>
  <img src="images/constructor-index.gif" width=275 height=38 alt="Constructor Index">
</h2>
<dl>
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#DatagramSocket()"><b>DatagramSocket</b></a>()
  <dd>  Constructs a datagram socket and binds it to any available port 
 on the local host machine.
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#DatagramSocket(int)"><b>DatagramSocket</b></a>(int)
  <dd>  Constructs a datagram socket and binds it to the specified port 
 on the local host machine.
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#DatagramSocket(int, java.net.InetAddress)"><b>DatagramSocket</b></a>(int, InetAddress)
  <dd>  Creates a datagram socket, bound to the specified local
 address.
</dl>
<h2>
  <img src="images/method-index.gif" width=207 height=38 alt="Method Index">
</h2>
<dl>
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#close()"><b>close</b></a>()
  <dd>  Closes this datagram socket.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getLocalAddress()"><b>getLocalAddress</b></a>()
  <dd>  Gets the local address to which the socket is bound.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getLocalPort()"><b>getLocalPort</b></a>()
  <dd>  Returns the port number on the local host to which this socket is bound.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getSoTimeout()"><b>getSoTimeout</b></a>()
  <dd>  Retrive setting for SO_TIMEOUT.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#receive(java.net.DatagramPacket)"><b>receive</b></a>(DatagramPacket)
  <dd>  Receives a datagram packet from this socket.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#send(java.net.DatagramPacket)"><b>send</b></a>(DatagramPacket)
  <dd>  Sends a datagram packet from this socket.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#setSoTimeout(int)"><b>setSoTimeout</b></a>(int)
  <dd> Enable/disable SO_TIMEOUT with the specified timeout, in
  milliseconds.
</dl>
<a name="constructors"></a>
<h2>
  <img src="images/constructors.gif" width=231 height=38 alt="Constructors">
</h2>
<a name="DatagramSocket"></a>
<a name="DatagramSocket()"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>DatagramSocket</b>
<pre>
 public DatagramSocket() throws <a href="java.net.SocketException.html#_top_">SocketException</a>
</pre>
<dl>
  <dd> Constructs a datagram socket and binds it to any available port 
 on the local host machine.
<p>
  <dd><dl>
    <dt> <b>Throws:</b> <a href="java.net.SocketException.html#_top_">SocketException</a>
    <dd> if the socket could not be opened,
               or the socket could not bind to the specified local port.
  </dl></dd>
</dl>
<a name="DatagramSocket(int)"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>DatagramSocket</b>
<pre>
 public DatagramSocket(int port) throws <a href="java.net.SocketException.html#_top_">SocketException</a>
</pre>
<dl>
  <dd> Constructs a datagram socket and binds it to the specified port 
 on the local host machine.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> local - port to use.
    <dt> <b>Throws:</b> <a href="java.net.SocketException.html#_top_">SocketException</a>
    <dd> if the socket could not be opened,
               or the socket could not bind to the specified local port.
  </dl></dd>
</dl>
<a name="DatagramSocket(int, java.net.InetAddress)"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>DatagramSocket</b>
<pre>
 public DatagramSocket(int port,
                       <a href="java.net.InetAddress.html#_top_">InetAddress</a> laddr) throws <a href="java.net.SocketException.html#_top_">SocketException</a>
</pre>
<dl>
  <dd> Creates a datagram socket, bound to the specified local
 address.  The local port must be between 0 and 65535 inclusive.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> port - local port to use
    <dd> laddr - local address to bind
  </dl></dd>
</dl>
<a name="methods"></a>
<h2>
  <img src="images/methods.gif" width=151 height=38 alt="Methods">
</h2>
<a name="send(java.net.DatagramPacket)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="send"><b>send</b></a>
<pre>
 public void send(<a href="java.net.DatagramPacket.html#_top_">DatagramPacket</a> p) throws <a href="java.io.IOException.html#_top_">IOException</a>
</pre>
<dl>
  <dd> Sends a datagram packet from this socket. The 
 <code>DatagramPacket</code> includes information indicating the 
 data to be sent, its length, the IP address of the remote host, 
 and the port number on the remote host.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> p - the <code>DatagramPacket</code> to be sent.
    <dt> <b>Throws:</b> <a href="java.io.IOException.html#_top_">IOException</a>
    <dd> if an I/O error occurs.
    <dt> <b>See Also:</b>
    <dd> <a href="java.net.DatagramPacket.html#_top_">DatagramPacket</a>
  </dl></dd>
</dl>
<a name="receive(java.net.DatagramPacket)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="receive"><b>receive</b></a>
<pre>
 public synchronized void receive(<a href="java.net.DatagramPacket.html#_top_">DatagramPacket</a> p) throws <a href="java.io.IOException.html#_top_">IOException</a>
</pre>
<dl>
  <dd> Receives a datagram packet from this socket. When this method 
 returns, the <code>DatagramPacket</code>'s buffer is filled with 
 the data received. The datagram packet also contains the sender's 
 IP address, and the port number on the sender's machine. 
 <p>
 This method blocks until a datagram is received. The 
 <code>length</code> field of the datagram packet object contains 
 the length of the received message. If the message is longer than 
 the buffer length, the message is truncated.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> p - the <code>DatagramPacket</code> into which to place
                 the incoming data.
    <dt> <b>Throws:</b> <a href="java.io.IOException.html#_top_">IOException</a>
    <dd> if an I/O error occurs.
    <dt> <b>See Also:</b>
    <dd> <a href="java.net.DatagramPacket.html#_top_">DatagramPacket</a>, <a href="#_top_">DatagramSocket</a>
  </dl></dd>
</dl>
<a name="getLocalAddress()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getLocalAddress"><b>getLocalAddress</b></a>
<pre>
 public <a href="java.net.InetAddress.html#_top_">InetAddress</a> getLocalAddress()
</pre>
<dl>
  <dd> Gets the local address to which the socket is bound.
<p>
</dl>
<a name="getLocalPort()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getLocalPort"><b>getLocalPort</b></a>
<pre>
 public int getLocalPort()
</pre>
<dl>
  <dd> Returns the port number on the local host to which this socket is bound.
<p>
  <dd><dl>
    <dt> <b>Returns:</b>
    <dd> the port number on the local host to which this socket is bound.
  </dl></dd>
</dl>
<a name="setSoTimeout(int)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="setSoTimeout"><b>setSoTimeout</b></a>
<pre>
 public synchronized void setSoTimeout(int timeout) throws <a href="java.net.SocketException.html#_top_">SocketException</a>
</pre>
<dl>
  <dd> 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 <B>java.io.InterruptedIOException</B> is raised, though the
  ServerSocket is still valid.  The option <B>must</B> 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.
<p>
</dl>
<a name="getSoTimeout()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getSoTimeout"><b>getSoTimeout</b></a>
<pre>
 public synchronized int getSoTimeout() throws <a href="java.net.SocketException.html#_top_">SocketException</a>
</pre>
<dl>
  <dd> Retrive setting for SO_TIMEOUT.  0 returns implies that the
 option is disabled (i.e., timeout of infinity).
<p>
</dl>
<a name="close()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="close"><b>close</b></a>
<pre>
 public void close()
</pre>
<dl>
  <dd> Closes this datagram socket.
<p>
</dl>
<hr>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.net.html">This Package</a>  <a href="java.net.DatagramPacket.html#_top_">Previous</a>  <a href="java.net.DatagramSocketImpl.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
</body>
</html>
