jdk/src/share/classes/java/net/Socket.java
changeset 19069 1d9cb0d080e3
parent 18274 7c4289125569
child 21334 c60dfce46a77
equal deleted inserted replaced
19068:f2358d18923a 19069:1d9cb0d080e3
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    37  * This class implements client sockets (also called just
    37  * This class implements client sockets (also called just
    38  * "sockets"). A socket is an endpoint for communication
    38  * "sockets"). A socket is an endpoint for communication
    39  * between two machines.
    39  * between two machines.
    40  * <p>
    40  * <p>
    41  * The actual work of the socket is performed by an instance of the
    41  * The actual work of the socket is performed by an instance of the
    42  * <code>SocketImpl</code> class. An application, by changing
    42  * {@code SocketImpl} class. An application, by changing
    43  * the socket factory that creates the socket implementation,
    43  * the socket factory that creates the socket implementation,
    44  * can configure itself to create sockets appropriate to the local
    44  * can configure itself to create sockets appropriate to the local
    45  * firewall.
    45  * firewall.
    46  *
    46  *
    47  * @author  unascribed
    47  * @author  unascribed
    86 
    86 
    87     /**
    87     /**
    88      * Creates an unconnected socket, specifying the type of proxy, if any,
    88      * Creates an unconnected socket, specifying the type of proxy, if any,
    89      * that should be used regardless of any other settings.
    89      * that should be used regardless of any other settings.
    90      * <P>
    90      * <P>
    91      * If there is a security manager, its <code>checkConnect</code> method
    91      * If there is a security manager, its {@code checkConnect} method
    92      * is called with the proxy host address and port number
    92      * is called with the proxy host address and port number
    93      * as its arguments. This could result in a SecurityException.
    93      * as its arguments. This could result in a SecurityException.
    94      * <P>
    94      * <P>
    95      * Examples:
    95      * Examples:
    96      * <UL> <LI><code>Socket s = new Socket(Proxy.NO_PROXY);</code> will create
    96      * <UL> <LI>{@code Socket s = new Socket(Proxy.NO_PROXY);} will create
    97      * a plain socket ignoring any other proxy configuration.</LI>
    97      * a plain socket ignoring any other proxy configuration.</LI>
    98      * <LI><code>Socket s = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("socks.mydom.com", 1080)));</code>
    98      * <LI>{@code Socket s = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("socks.mydom.com", 1080)));}
    99      * will create a socket connecting through the specified SOCKS proxy
    99      * will create a socket connecting through the specified SOCKS proxy
   100      * server.</LI>
   100      * server.</LI>
   101      * </UL>
   101      * </UL>
   102      *
   102      *
   103      * @param proxy a {@link java.net.Proxy Proxy} object specifying what kind
   103      * @param proxy a {@link java.net.Proxy Proxy} object specifying what kind
   104      *              of proxying should be used.
   104      *              of proxying should be used.
   105      * @throws IllegalArgumentException if the proxy is of an invalid type
   105      * @throws IllegalArgumentException if the proxy is of an invalid type
   106      *          or <code>null</code>.
   106      *          or {@code null}.
   107      * @throws SecurityException if a security manager is present and
   107      * @throws SecurityException if a security manager is present and
   108      *                           permission to connect to the proxy is
   108      *                           permission to connect to the proxy is
   109      *                           denied.
   109      *                           denied.
   110      * @see java.net.ProxySelector
   110      * @see java.net.ProxySelector
   111      * @see java.net.Proxy
   111      * @see java.net.Proxy
   171 
   171 
   172     /**
   172     /**
   173      * Creates a stream socket and connects it to the specified port
   173      * Creates a stream socket and connects it to the specified port
   174      * number on the named host.
   174      * number on the named host.
   175      * <p>
   175      * <p>
   176      * If the specified host is <tt>null</tt> it is the equivalent of
   176      * If the specified host is {@code null} it is the equivalent of
   177      * specifying the address as <tt>{@link java.net.InetAddress#getByName InetAddress.getByName}(null)</tt>.
   177      * specifying the address as
       
   178      * {@link java.net.InetAddress#getByName InetAddress.getByName}{@code (null)}.
   178      * In other words, it is equivalent to specifying an address of the
   179      * In other words, it is equivalent to specifying an address of the
   179      * loopback interface. </p>
   180      * loopback interface. </p>
   180      * <p>
   181      * <p>
   181      * If the application has specified a server socket factory, that
   182      * If the application has specified a server socket factory, that
   182      * factory's <code>createSocketImpl</code> method is called to create
   183      * factory's {@code createSocketImpl} method is called to create
   183      * the actual socket implementation. Otherwise a "plain" socket is created.
   184      * the actual socket implementation. Otherwise a "plain" socket is created.
   184      * <p>
   185      * <p>
   185      * If there is a security manager, its
   186      * If there is a security manager, its
   186      * <code>checkConnect</code> method is called
   187      * {@code checkConnect} method is called
   187      * with the host address and <code>port</code>
   188      * with the host address and {@code port}
   188      * as its arguments. This could result in a SecurityException.
   189      * as its arguments. This could result in a SecurityException.
   189      *
   190      *
   190      * @param      host   the host name, or <code>null</code> for the loopback address.
   191      * @param      host   the host name, or {@code null} for the loopback address.
   191      * @param      port   the port number.
   192      * @param      port   the port number.
   192      *
   193      *
   193      * @exception  UnknownHostException if the IP address of
   194      * @exception  UnknownHostException if the IP address of
   194      * the host could not be determined.
   195      * the host could not be determined.
   195      *
   196      *
   196      * @exception  IOException  if an I/O error occurs when creating the socket.
   197      * @exception  IOException  if an I/O error occurs when creating the socket.
   197      * @exception  SecurityException  if a security manager exists and its
   198      * @exception  SecurityException  if a security manager exists and its
   198      *             <code>checkConnect</code> method doesn't allow the operation.
   199      *             {@code checkConnect} method doesn't allow the operation.
   199      * @exception  IllegalArgumentException if the port parameter is outside
   200      * @exception  IllegalArgumentException if the port parameter is outside
   200      *             the specified range of valid port values, which is between
   201      *             the specified range of valid port values, which is between
   201      *             0 and 65535, inclusive.
   202      *             0 and 65535, inclusive.
   202      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
   203      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
   203      * @see        java.net.SocketImpl
   204      * @see        java.net.SocketImpl
   215     /**
   216     /**
   216      * Creates a stream socket and connects it to the specified port
   217      * Creates a stream socket and connects it to the specified port
   217      * number at the specified IP address.
   218      * number at the specified IP address.
   218      * <p>
   219      * <p>
   219      * If the application has specified a socket factory, that factory's
   220      * If the application has specified a socket factory, that factory's
   220      * <code>createSocketImpl</code> method is called to create the
   221      * {@code createSocketImpl} method is called to create the
   221      * actual socket implementation. Otherwise a "plain" socket is created.
   222      * actual socket implementation. Otherwise a "plain" socket is created.
   222      * <p>
   223      * <p>
   223      * If there is a security manager, its
   224      * If there is a security manager, its
   224      * <code>checkConnect</code> method is called
   225      * {@code checkConnect} method is called
   225      * with the host address and <code>port</code>
   226      * with the host address and {@code port}
   226      * as its arguments. This could result in a SecurityException.
   227      * as its arguments. This could result in a SecurityException.
   227      *
   228      *
   228      * @param      address   the IP address.
   229      * @param      address   the IP address.
   229      * @param      port      the port number.
   230      * @param      port      the port number.
   230      * @exception  IOException  if an I/O error occurs when creating the socket.
   231      * @exception  IOException  if an I/O error occurs when creating the socket.
   231      * @exception  SecurityException  if a security manager exists and its
   232      * @exception  SecurityException  if a security manager exists and its
   232      *             <code>checkConnect</code> method doesn't allow the operation.
   233      *             {@code checkConnect} method doesn't allow the operation.
   233      * @exception  IllegalArgumentException if the port parameter is outside
   234      * @exception  IllegalArgumentException if the port parameter is outside
   234      *             the specified range of valid port values, which is between
   235      *             the specified range of valid port values, which is between
   235      *             0 and 65535, inclusive.
   236      *             0 and 65535, inclusive.
   236      * @exception  NullPointerException if <code>address</code> is null.
   237      * @exception  NullPointerException if {@code address} is null.
   237      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
   238      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
   238      * @see        java.net.SocketImpl
   239      * @see        java.net.SocketImpl
   239      * @see        java.net.SocketImplFactory#createSocketImpl()
   240      * @see        java.net.SocketImplFactory#createSocketImpl()
   240      * @see        SecurityManager#checkConnect
   241      * @see        SecurityManager#checkConnect
   241      */
   242      */
   247     /**
   248     /**
   248      * Creates a socket and connects it to the specified remote host on
   249      * Creates a socket and connects it to the specified remote host on
   249      * the specified remote port. The Socket will also bind() to the local
   250      * the specified remote port. The Socket will also bind() to the local
   250      * address and port supplied.
   251      * address and port supplied.
   251      * <p>
   252      * <p>
   252      * If the specified host is <tt>null</tt> it is the equivalent of
   253      * If the specified host is {@code null} it is the equivalent of
   253      * specifying the address as <tt>{@link java.net.InetAddress#getByName InetAddress.getByName}(null)</tt>.
   254      * specifying the address as
       
   255      * {@link java.net.InetAddress#getByName InetAddress.getByName}{@code (null)}.
   254      * In other words, it is equivalent to specifying an address of the
   256      * In other words, it is equivalent to specifying an address of the
   255      * loopback interface. </p>
   257      * loopback interface. </p>
   256      * <p>
   258      * <p>
   257      * A local port number of <code>zero</code> will let the system pick up a
   259      * A local port number of {@code zero} will let the system pick up a
   258      * free port in the <code>bind</code> operation.</p>
   260      * free port in the {@code bind} operation.</p>
   259      * <p>
   261      * <p>
   260      * If there is a security manager, its
   262      * If there is a security manager, its
   261      * <code>checkConnect</code> method is called
   263      * {@code checkConnect} method is called
   262      * with the host address and <code>port</code>
   264      * with the host address and {@code port}
   263      * as its arguments. This could result in a SecurityException.
   265      * as its arguments. This could result in a SecurityException.
   264      *
   266      *
   265      * @param host the name of the remote host, or <code>null</code> for the loopback address.
   267      * @param host the name of the remote host, or {@code null} for the loopback address.
   266      * @param port the remote port
   268      * @param port the remote port
   267      * @param localAddr the local address the socket is bound to, or
   269      * @param localAddr the local address the socket is bound to, or
   268      *        <code>null</code> for the <code>anyLocal</code> address.
   270      *        {@code null} for the {@code anyLocal} address.
   269      * @param localPort the local port the socket is bound to, or
   271      * @param localPort the local port the socket is bound to, or
   270      *        <code>zero</code> for a system selected free port.
   272      *        {@code zero} for a system selected free port.
   271      * @exception  IOException  if an I/O error occurs when creating the socket.
   273      * @exception  IOException  if an I/O error occurs when creating the socket.
   272      * @exception  SecurityException  if a security manager exists and its
   274      * @exception  SecurityException  if a security manager exists and its
   273      *             <code>checkConnect</code> method doesn't allow the operation.
   275      *             {@code checkConnect} method doesn't allow the operation.
   274      * @exception  IllegalArgumentException if the port parameter or localPort
   276      * @exception  IllegalArgumentException if the port parameter or localPort
   275      *             parameter is outside the specified range of valid port values,
   277      *             parameter is outside the specified range of valid port values,
   276      *             which is between 0 and 65535, inclusive.
   278      *             which is between 0 and 65535, inclusive.
   277      * @see        SecurityManager#checkConnect
   279      * @see        SecurityManager#checkConnect
   278      * @since   JDK1.1
   280      * @since   JDK1.1
   287     /**
   289     /**
   288      * Creates a socket and connects it to the specified remote address on
   290      * Creates a socket and connects it to the specified remote address on
   289      * the specified remote port. The Socket will also bind() to the local
   291      * the specified remote port. The Socket will also bind() to the local
   290      * address and port supplied.
   292      * address and port supplied.
   291      * <p>
   293      * <p>
   292      * If the specified local address is <tt>null</tt> it is the equivalent of
   294      * If the specified local address is {@code null} it is the equivalent of
   293      * specifying the address as the AnyLocal address (see <tt>{@link java.net.InetAddress#isAnyLocalAddress InetAddress.isAnyLocalAddress}()</tt>).
   295      * specifying the address as the AnyLocal address
   294      * <p>
   296      * (see {@link java.net.InetAddress#isAnyLocalAddress InetAddress.isAnyLocalAddress}{@code ()}).
   295      * A local port number of <code>zero</code> will let the system pick up a
   297      * <p>
   296      * free port in the <code>bind</code> operation.</p>
   298      * A local port number of {@code zero} will let the system pick up a
       
   299      * free port in the {@code bind} operation.</p>
   297      * <p>
   300      * <p>
   298      * If there is a security manager, its
   301      * If there is a security manager, its
   299      * <code>checkConnect</code> method is called
   302      * {@code checkConnect} method is called
   300      * with the host address and <code>port</code>
   303      * with the host address and {@code port}
   301      * as its arguments. This could result in a SecurityException.
   304      * as its arguments. This could result in a SecurityException.
   302      *
   305      *
   303      * @param address the remote address
   306      * @param address the remote address
   304      * @param port the remote port
   307      * @param port the remote port
   305      * @param localAddr the local address the socket is bound to, or
   308      * @param localAddr the local address the socket is bound to, or
   306      *        <code>null</code> for the <code>anyLocal</code> address.
   309      *        {@code null} for the {@code anyLocal} address.
   307      * @param localPort the local port the socket is bound to or
   310      * @param localPort the local port the socket is bound to or
   308      *        <code>zero</code> for a system selected free port.
   311      *        {@code zero} for a system selected free port.
   309      * @exception  IOException  if an I/O error occurs when creating the socket.
   312      * @exception  IOException  if an I/O error occurs when creating the socket.
   310      * @exception  SecurityException  if a security manager exists and its
   313      * @exception  SecurityException  if a security manager exists and its
   311      *             <code>checkConnect</code> method doesn't allow the operation.
   314      *             {@code checkConnect} method doesn't allow the operation.
   312      * @exception  IllegalArgumentException if the port parameter or localPort
   315      * @exception  IllegalArgumentException if the port parameter or localPort
   313      *             parameter is outside the specified range of valid port values,
   316      *             parameter is outside the specified range of valid port values,
   314      *             which is between 0 and 65535, inclusive.
   317      *             which is between 0 and 65535, inclusive.
   315      * @exception  NullPointerException if <code>address</code> is null.
   318      * @exception  NullPointerException if {@code address} is null.
   316      * @see        SecurityManager#checkConnect
   319      * @see        SecurityManager#checkConnect
   317      * @since   JDK1.1
   320      * @since   JDK1.1
   318      */
   321      */
   319     public Socket(InetAddress address, int port, InetAddress localAddr,
   322     public Socket(InetAddress address, int port, InetAddress localAddr,
   320                   int localPort) throws IOException {
   323                   int localPort) throws IOException {
   324 
   327 
   325     /**
   328     /**
   326      * Creates a stream socket and connects it to the specified port
   329      * Creates a stream socket and connects it to the specified port
   327      * number on the named host.
   330      * number on the named host.
   328      * <p>
   331      * <p>
   329      * If the specified host is <tt>null</tt> it is the equivalent of
   332      * If the specified host is {@code null} it is the equivalent of
   330      * specifying the address as <tt>{@link java.net.InetAddress#getByName InetAddress.getByName}(null)</tt>.
   333      * specifying the address as
       
   334      * {@link java.net.InetAddress#getByName InetAddress.getByName}{@code (null)}.
   331      * In other words, it is equivalent to specifying an address of the
   335      * In other words, it is equivalent to specifying an address of the
   332      * loopback interface. </p>
   336      * loopback interface. </p>
   333      * <p>
   337      * <p>
   334      * If the stream argument is <code>true</code>, this creates a
   338      * If the stream argument is {@code true}, this creates a
   335      * stream socket. If the stream argument is <code>false</code>, it
   339      * stream socket. If the stream argument is {@code false}, it
   336      * creates a datagram socket.
   340      * creates a datagram socket.
   337      * <p>
   341      * <p>
   338      * If the application has specified a server socket factory, that
   342      * If the application has specified a server socket factory, that
   339      * factory's <code>createSocketImpl</code> method is called to create
   343      * factory's {@code createSocketImpl} method is called to create
   340      * the actual socket implementation. Otherwise a "plain" socket is created.
   344      * the actual socket implementation. Otherwise a "plain" socket is created.
   341      * <p>
   345      * <p>
   342      * If there is a security manager, its
   346      * If there is a security manager, its
   343      * <code>checkConnect</code> method is called
   347      * {@code checkConnect} method is called
   344      * with the host address and <code>port</code>
   348      * with the host address and {@code port}
   345      * as its arguments. This could result in a SecurityException.
   349      * as its arguments. This could result in a SecurityException.
   346      * <p>
   350      * <p>
   347      * If a UDP socket is used, TCP/IP related socket options will not apply.
   351      * If a UDP socket is used, TCP/IP related socket options will not apply.
   348      *
   352      *
   349      * @param      host     the host name, or <code>null</code> for the loopback address.
   353      * @param      host     the host name, or {@code null} for the loopback address.
   350      * @param      port     the port number.
   354      * @param      port     the port number.
   351      * @param      stream   a <code>boolean</code> indicating whether this is
   355      * @param      stream   a {@code boolean} indicating whether this is
   352      *                      a stream socket or a datagram socket.
   356      *                      a stream socket or a datagram socket.
   353      * @exception  IOException  if an I/O error occurs when creating the socket.
   357      * @exception  IOException  if an I/O error occurs when creating the socket.
   354      * @exception  SecurityException  if a security manager exists and its
   358      * @exception  SecurityException  if a security manager exists and its
   355      *             <code>checkConnect</code> method doesn't allow the operation.
   359      *             {@code checkConnect} method doesn't allow the operation.
   356      * @exception  IllegalArgumentException if the port parameter is outside
   360      * @exception  IllegalArgumentException if the port parameter is outside
   357      *             the specified range of valid port values, which is between
   361      *             the specified range of valid port values, which is between
   358      *             0 and 65535, inclusive.
   362      *             0 and 65535, inclusive.
   359      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
   363      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
   360      * @see        java.net.SocketImpl
   364      * @see        java.net.SocketImpl
   371 
   375 
   372     /**
   376     /**
   373      * Creates a socket and connects it to the specified port number at
   377      * Creates a socket and connects it to the specified port number at
   374      * the specified IP address.
   378      * the specified IP address.
   375      * <p>
   379      * <p>
   376      * If the stream argument is <code>true</code>, this creates a
   380      * If the stream argument is {@code true}, this creates a
   377      * stream socket. If the stream argument is <code>false</code>, it
   381      * stream socket. If the stream argument is {@code false}, it
   378      * creates a datagram socket.
   382      * creates a datagram socket.
   379      * <p>
   383      * <p>
   380      * If the application has specified a server socket factory, that
   384      * If the application has specified a server socket factory, that
   381      * factory's <code>createSocketImpl</code> method is called to create
   385      * factory's {@code createSocketImpl} method is called to create
   382      * the actual socket implementation. Otherwise a "plain" socket is created.
   386      * the actual socket implementation. Otherwise a "plain" socket is created.
   383      *
   387      *
   384      * <p>If there is a security manager, its
   388      * <p>If there is a security manager, its
   385      * <code>checkConnect</code> method is called
   389      * {@code checkConnect} method is called
   386      * with <code>host.getHostAddress()</code> and <code>port</code>
   390      * with {@code host.getHostAddress()} and {@code port}
   387      * as its arguments. This could result in a SecurityException.
   391      * as its arguments. This could result in a SecurityException.
   388      * <p>
   392      * <p>
   389      * If UDP socket is used, TCP/IP related socket options will not apply.
   393      * If UDP socket is used, TCP/IP related socket options will not apply.
   390      *
   394      *
   391      * @param      host     the IP address.
   395      * @param      host     the IP address.
   392      * @param      port      the port number.
   396      * @param      port      the port number.
   393      * @param      stream    if <code>true</code>, create a stream socket;
   397      * @param      stream    if {@code true}, create a stream socket;
   394      *                       otherwise, create a datagram socket.
   398      *                       otherwise, create a datagram socket.
   395      * @exception  IOException  if an I/O error occurs when creating the socket.
   399      * @exception  IOException  if an I/O error occurs when creating the socket.
   396      * @exception  SecurityException  if a security manager exists and its
   400      * @exception  SecurityException  if a security manager exists and its
   397      *             <code>checkConnect</code> method doesn't allow the operation.
   401      *             {@code checkConnect} method doesn't allow the operation.
   398      * @exception  IllegalArgumentException if the port parameter is outside
   402      * @exception  IllegalArgumentException if the port parameter is outside
   399      *             the specified range of valid port values, which is between
   403      *             the specified range of valid port values, which is between
   400      *             0 and 65535, inclusive.
   404      *             0 and 65535, inclusive.
   401      * @exception  NullPointerException if <code>host</code> is null.
   405      * @exception  NullPointerException if {@code host} is null.
   402      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
   406      * @see        java.net.Socket#setSocketImplFactory(java.net.SocketImplFactory)
   403      * @see        java.net.SocketImpl
   407      * @see        java.net.SocketImpl
   404      * @see        java.net.SocketImplFactory#createSocketImpl()
   408      * @see        java.net.SocketImplFactory#createSocketImpl()
   405      * @see        SecurityManager#checkConnect
   409      * @see        SecurityManager#checkConnect
   406      * @deprecated Use DatagramSocket instead for UDP transport.
   410      * @deprecated Use DatagramSocket instead for UDP transport.
   435     }
   439     }
   436 
   440 
   437     /**
   441     /**
   438      * Creates the socket implementation.
   442      * Creates the socket implementation.
   439      *
   443      *
   440      * @param stream a <code>boolean</code> value : <code>true</code> for a TCP socket,
   444      * @param stream a {@code boolean} value : {@code true} for a TCP socket,
   441      *               <code>false</code> for UDP.
   445      *               {@code false} for UDP.
   442      * @throws IOException if creation fails
   446      * @throws IOException if creation fails
   443      * @since 1.4
   447      * @since 1.4
   444      */
   448      */
   445      void createImpl(boolean stream) throws SocketException {
   449      void createImpl(boolean stream) throws SocketException {
   446         if (impl == null)
   450         if (impl == null)
   498             impl.setSocket(this);
   502             impl.setSocket(this);
   499     }
   503     }
   500 
   504 
   501 
   505 
   502     /**
   506     /**
   503      * Get the <code>SocketImpl</code> attached to this socket, creating
   507      * Get the {@code SocketImpl} attached to this socket, creating
   504      * it if necessary.
   508      * it if necessary.
   505      *
   509      *
   506      * @return  the <code>SocketImpl</code> attached to that ServerSocket.
   510      * @return  the {@code SocketImpl} attached to that ServerSocket.
   507      * @throws SocketException if creation fails
   511      * @throws SocketException if creation fails
   508      * @since 1.4
   512      * @since 1.4
   509      */
   513      */
   510     SocketImpl getImpl() throws SocketException {
   514     SocketImpl getImpl() throws SocketException {
   511         if (!created)
   515         if (!created)
   514     }
   518     }
   515 
   519 
   516     /**
   520     /**
   517      * Connects this socket to the server.
   521      * Connects this socket to the server.
   518      *
   522      *
   519      * @param   endpoint the <code>SocketAddress</code>
   523      * @param   endpoint the {@code SocketAddress}
   520      * @throws  IOException if an error occurs during the connection
   524      * @throws  IOException if an error occurs during the connection
   521      * @throws  java.nio.channels.IllegalBlockingModeException
   525      * @throws  java.nio.channels.IllegalBlockingModeException
   522      *          if this socket has an associated channel,
   526      *          if this socket has an associated channel,
   523      *          and the channel is in non-blocking mode
   527      *          and the channel is in non-blocking mode
   524      * @throws  IllegalArgumentException if endpoint is null or is a
   528      * @throws  IllegalArgumentException if endpoint is null or is a
   533     /**
   537     /**
   534      * Connects this socket to the server with a specified timeout value.
   538      * Connects this socket to the server with a specified timeout value.
   535      * A timeout of zero is interpreted as an infinite timeout. The connection
   539      * A timeout of zero is interpreted as an infinite timeout. The connection
   536      * will then block until established or an error occurs.
   540      * will then block until established or an error occurs.
   537      *
   541      *
   538      * @param   endpoint the <code>SocketAddress</code>
   542      * @param   endpoint the {@code SocketAddress}
   539      * @param   timeout  the timeout value to be used in milliseconds.
   543      * @param   timeout  the timeout value to be used in milliseconds.
   540      * @throws  IOException if an error occurs during the connection
   544      * @throws  IOException if an error occurs during the connection
   541      * @throws  SocketTimeoutException if timeout expires before connecting
   545      * @throws  SocketTimeoutException if timeout expires before connecting
   542      * @throws  java.nio.channels.IllegalBlockingModeException
   546      * @throws  java.nio.channels.IllegalBlockingModeException
   543      *          if this socket has an associated channel,
   547      *          if this socket has an associated channel,
   595     }
   599     }
   596 
   600 
   597     /**
   601     /**
   598      * Binds the socket to a local address.
   602      * Binds the socket to a local address.
   599      * <P>
   603      * <P>
   600      * If the address is <code>null</code>, then the system will pick up
   604      * If the address is {@code null}, then the system will pick up
   601      * an ephemeral port and a valid local address to bind the socket.
   605      * an ephemeral port and a valid local address to bind the socket.
   602      *
   606      *
   603      * @param   bindpoint the <code>SocketAddress</code> to bind to
   607      * @param   bindpoint the {@code SocketAddress} to bind to
   604      * @throws  IOException if the bind operation fails, or if the socket
   608      * @throws  IOException if the bind operation fails, or if the socket
   605      *                     is already bound.
   609      *                     is already bound.
   606      * @throws  IllegalArgumentException if bindpoint is a
   610      * @throws  IllegalArgumentException if bindpoint is a
   607      *          SocketAddress subclass not supported by this socket
   611      *          SocketAddress subclass not supported by this socket
   608      *
   612      *
   666      * If the socket was connected prior to being {@link #close closed},
   670      * If the socket was connected prior to being {@link #close closed},
   667      * then this method will continue to return the connected address
   671      * then this method will continue to return the connected address
   668      * after the socket is closed.
   672      * after the socket is closed.
   669      *
   673      *
   670      * @return  the remote IP address to which this socket is connected,
   674      * @return  the remote IP address to which this socket is connected,
   671      *          or <code>null</code> if the socket is not connected.
   675      *          or {@code null} if the socket is not connected.
   672      */
   676      */
   673     public InetAddress getInetAddress() {
   677     public InetAddress getInetAddress() {
   674         if (!isConnected())
   678         if (!isConnected())
   675             return null;
   679             return null;
   676         try {
   680         try {
   758         return -1;
   762         return -1;
   759     }
   763     }
   760 
   764 
   761     /**
   765     /**
   762      * Returns the address of the endpoint this socket is connected to, or
   766      * Returns the address of the endpoint this socket is connected to, or
   763      * <code>null</code> if it is unconnected.
   767      * {@code null} if it is unconnected.
   764      * <p>
   768      * <p>
   765      * If the socket was connected prior to being {@link #close closed},
   769      * If the socket was connected prior to being {@link #close closed},
   766      * then this method will continue to return the connected address
   770      * then this method will continue to return the connected address
   767      * after the socket is closed.
   771      * after the socket is closed.
   768      *
   772      *
   769 
   773 
   770      * @return a <code>SocketAddress</code> representing the remote endpoint of this
   774      * @return a {@code SocketAddress} representing the remote endpoint of this
   771      *         socket, or <code>null</code> if it is not connected yet.
   775      *         socket, or {@code null} if it is not connected yet.
   772      * @see #getInetAddress()
   776      * @see #getInetAddress()
   773      * @see #getPort()
   777      * @see #getPort()
   774      * @see #connect(SocketAddress, int)
   778      * @see #connect(SocketAddress, int)
   775      * @see #connect(SocketAddress)
   779      * @see #connect(SocketAddress)
   776      * @since 1.4
   780      * @since 1.4
   783 
   787 
   784     /**
   788     /**
   785      * Returns the address of the endpoint this socket is bound to.
   789      * Returns the address of the endpoint this socket is bound to.
   786      * <p>
   790      * <p>
   787      * If a socket bound to an endpoint represented by an
   791      * If a socket bound to an endpoint represented by an
   788      * <code>InetSocketAddress </code> is {@link #close closed},
   792      * {@code InetSocketAddress } is {@link #close closed},
   789      * then this method will continue to return an <code>InetSocketAddress</code>
   793      * then this method will continue to return an {@code InetSocketAddress}
   790      * after the socket is closed. In that case the returned
   794      * after the socket is closed. In that case the returned
   791      * <code>InetSocketAddress</code>'s address is the
   795      * {@code InetSocketAddress}'s address is the
   792      * {@link InetAddress#isAnyLocalAddress wildcard} address
   796      * {@link InetAddress#isAnyLocalAddress wildcard} address
   793      * and its port is the local port that it was bound to.
   797      * and its port is the local port that it was bound to.
   794      * <p>
   798      * <p>
   795      * If there is a security manager set, its {@code checkConnect} method is
   799      * If there is a security manager set, its {@code checkConnect} method is
   796      * called with the local address and {@code -1} as its arguments to see
   800      * called with the local address and {@code -1} as its arguments to see
   826      * SocketChannel.open} or {@link
   830      * SocketChannel.open} or {@link
   827      * java.nio.channels.ServerSocketChannel#accept ServerSocketChannel.accept}
   831      * java.nio.channels.ServerSocketChannel#accept ServerSocketChannel.accept}
   828      * methods.
   832      * methods.
   829      *
   833      *
   830      * @return  the socket channel associated with this socket,
   834      * @return  the socket channel associated with this socket,
   831      *          or <tt>null</tt> if this socket was not created
   835      *          or {@code null} if this socket was not created
   832      *          for a channel
   836      *          for a channel
   833      *
   837      *
   834      * @since 1.4
   838      * @since 1.4
   835      * @spec JSR-51
   839      * @spec JSR-51
   836      */
   840      */
   841     /**
   845     /**
   842      * Returns an input stream for this socket.
   846      * Returns an input stream for this socket.
   843      *
   847      *
   844      * <p> If this socket has an associated channel then the resulting input
   848      * <p> If this socket has an associated channel then the resulting input
   845      * stream delegates all of its operations to the channel.  If the channel
   849      * stream delegates all of its operations to the channel.  If the channel
   846      * is in non-blocking mode then the input stream's <tt>read</tt> operations
   850      * is in non-blocking mode then the input stream's {@code read} operations
   847      * will throw an {@link java.nio.channels.IllegalBlockingModeException}.
   851      * will throw an {@link java.nio.channels.IllegalBlockingModeException}.
   848      *
   852      *
   849      * <p>Under abnormal conditions the underlying connection may be
   853      * <p>Under abnormal conditions the underlying connection may be
   850      * broken by the remote host or the network software (for example
   854      * broken by the remote host or the network software (for example
   851      * a connection reset in the case of TCP connections). When a
   855      * a connection reset in the case of TCP connections). When a
   865      *   {@link java.io.IOException IOException}.
   869      *   {@link java.io.IOException IOException}.
   866      *
   870      *
   867      *   <li><p>If there are no bytes buffered on the socket, and the
   871      *   <li><p>If there are no bytes buffered on the socket, and the
   868      *   socket has not been closed using {@link #close close}, then
   872      *   socket has not been closed using {@link #close close}, then
   869      *   {@link java.io.InputStream#available available} will
   873      *   {@link java.io.InputStream#available available} will
   870      *   return <code>0</code>.
   874      *   return {@code 0}.
   871      *
   875      *
   872      * </ul>
   876      * </ul>
   873      *
   877      *
   874      * <p> Closing the returned {@link java.io.InputStream InputStream}
   878      * <p> Closing the returned {@link java.io.InputStream InputStream}
   875      * will close the associated socket.
   879      * will close the associated socket.
   908     /**
   912     /**
   909      * Returns an output stream for this socket.
   913      * Returns an output stream for this socket.
   910      *
   914      *
   911      * <p> If this socket has an associated channel then the resulting output
   915      * <p> If this socket has an associated channel then the resulting output
   912      * stream delegates all of its operations to the channel.  If the channel
   916      * stream delegates all of its operations to the channel.  If the channel
   913      * is in non-blocking mode then the output stream's <tt>write</tt>
   917      * is in non-blocking mode then the output stream's {@code write}
   914      * operations will throw an {@link
   918      * operations will throw an {@link
   915      * java.nio.channels.IllegalBlockingModeException}.
   919      * java.nio.channels.IllegalBlockingModeException}.
   916      *
   920      *
   917      * <p> Closing the returned {@link java.io.OutputStream OutputStream}
   921      * <p> Closing the returned {@link java.io.OutputStream OutputStream}
   918      * will close the associated socket.
   922      * will close the associated socket.
   947 
   951 
   948     /**
   952     /**
   949      * Enable/disable {@link SocketOptions#TCP_NODELAY TCP_NODELAY}
   953      * Enable/disable {@link SocketOptions#TCP_NODELAY TCP_NODELAY}
   950      * (disable/enable Nagle's algorithm).
   954      * (disable/enable Nagle's algorithm).
   951      *
   955      *
   952      * @param on <code>true</code> to enable TCP_NODELAY,
   956      * @param on {@code true} to enable TCP_NODELAY,
   953      * <code>false</code> to disable.
   957      * {@code false} to disable.
   954      *
   958      *
   955      * @exception SocketException if there is an error
   959      * @exception SocketException if there is an error
   956      * in the underlying protocol, such as a TCP error.
   960      * in the underlying protocol, such as a TCP error.
   957      *
   961      *
   958      * @since   JDK1.1
   962      * @since   JDK1.1
   966     }
   970     }
   967 
   971 
   968     /**
   972     /**
   969      * Tests if {@link SocketOptions#TCP_NODELAY TCP_NODELAY} is enabled.
   973      * Tests if {@link SocketOptions#TCP_NODELAY TCP_NODELAY} is enabled.
   970      *
   974      *
   971      * @return a <code>boolean</code> indicating whether or not
   975      * @return a {@code boolean} indicating whether or not
   972      *         {@link SocketOptions#TCP_NODELAY TCP_NODELAY} is enabled.
   976      *         {@link SocketOptions#TCP_NODELAY TCP_NODELAY} is enabled.
   973      * @exception SocketException if there is an error
   977      * @exception SocketException if there is an error
   974      * in the underlying protocol, such as a TCP error.
   978      * in the underlying protocol, such as a TCP error.
   975      * @since   JDK1.1
   979      * @since   JDK1.1
   976      * @see #setTcpNoDelay(boolean)
   980      * @see #setTcpNoDelay(boolean)
  1064      * Note, only limited support is provided for handling incoming urgent
  1068      * Note, only limited support is provided for handling incoming urgent
  1065      * data. In particular, no notification of incoming urgent data is provided
  1069      * data. In particular, no notification of incoming urgent data is provided
  1066      * and there is no capability to distinguish between normal data and urgent
  1070      * and there is no capability to distinguish between normal data and urgent
  1067      * data unless provided by a higher level protocol.
  1071      * data unless provided by a higher level protocol.
  1068      *
  1072      *
  1069      * @param on <code>true</code> to enable
  1073      * @param on {@code true} to enable
  1070      *           {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE},
  1074      *           {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE},
  1071      *           <code>false</code> to disable.
  1075      *           {@code false} to disable.
  1072      *
  1076      *
  1073      * @exception SocketException if there is an error
  1077      * @exception SocketException if there is an error
  1074      * in the underlying protocol, such as a TCP error.
  1078      * in the underlying protocol, such as a TCP error.
  1075      *
  1079      *
  1076      * @since   1.4
  1080      * @since   1.4
  1084     }
  1088     }
  1085 
  1089 
  1086     /**
  1090     /**
  1087      * Tests if {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE} is enabled.
  1091      * Tests if {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE} is enabled.
  1088      *
  1092      *
  1089      * @return a <code>boolean</code> indicating whether or not
  1093      * @return a {@code boolean} indicating whether or not
  1090      *         {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE}is enabled.
  1094      *         {@link SocketOptions#SO_OOBINLINE SO_OOBINLINE}is enabled.
  1091      *
  1095      *
  1092      * @exception SocketException if there is an error
  1096      * @exception SocketException if there is an error
  1093      * in the underlying protocol, such as a TCP error.
  1097      * in the underlying protocol, such as a TCP error.
  1094      * @since   1.4
  1098      * @since   1.4
  1149         }
  1153         }
  1150     }
  1154     }
  1151 
  1155 
  1152     /**
  1156     /**
  1153      * Sets the {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option to the
  1157      * Sets the {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option to the
  1154      * specified value for this <tt>Socket</tt>.
  1158      * specified value for this {@code Socket}.
  1155      * The {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option is used by the
  1159      * The {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option is used by the
  1156      * platform's networking code as a hint for the size to set the underlying
  1160      * platform's networking code as a hint for the size to set the underlying
  1157      * network I/O buffers.
  1161      * network I/O buffers.
  1158      *
  1162      *
  1159      * <p>Because {@link SocketOptions#SO_SNDBUF SO_SNDBUF} is a hint,
  1163      * <p>Because {@link SocketOptions#SO_SNDBUF SO_SNDBUF} is a hint,
  1182         getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size));
  1186         getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size));
  1183     }
  1187     }
  1184 
  1188 
  1185     /**
  1189     /**
  1186      * Get value of the {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option
  1190      * Get value of the {@link SocketOptions#SO_SNDBUF SO_SNDBUF} option
  1187      * for this <tt>Socket</tt>, that is the buffer size used by the platform
  1191      * for this {@code Socket}, that is the buffer size used by the platform
  1188      * for output on this <tt>Socket</tt>.
  1192      * for output on this {@code Socket}.
  1189      * @return the value of the {@link SocketOptions#SO_SNDBUF SO_SNDBUF}
  1193      * @return the value of the {@link SocketOptions#SO_SNDBUF SO_SNDBUF}
  1190      *         option for this <tt>Socket</tt>.
  1194      *         option for this {@code Socket}.
  1191      *
  1195      *
  1192      * @exception SocketException if there is an error
  1196      * @exception SocketException if there is an error
  1193      * in the underlying protocol, such as a TCP error.
  1197      * in the underlying protocol, such as a TCP error.
  1194      *
  1198      *
  1195      * @see #setSendBufferSize(int)
  1199      * @see #setSendBufferSize(int)
  1206         return result;
  1210         return result;
  1207     }
  1211     }
  1208 
  1212 
  1209     /**
  1213     /**
  1210      * Sets the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option to the
  1214      * Sets the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option to the
  1211      * specified value for this <tt>Socket</tt>. The
  1215      * specified value for this {@code Socket}. The
  1212      * {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option is
  1216      * {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option is
  1213      * used by the platform's networking code as a hint for the size to set
  1217      * used by the platform's networking code as a hint for the size to set
  1214      * the underlying network I/O buffers.
  1218      * the underlying network I/O buffers.
  1215      *
  1219      *
  1216      * <p>Increasing the receive buffer size can increase the performance of
  1220      * <p>Increasing the receive buffer size can increase the performance of
  1256         getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
  1260         getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
  1257     }
  1261     }
  1258 
  1262 
  1259     /**
  1263     /**
  1260      * Gets the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option
  1264      * Gets the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF} option
  1261      * for this <tt>Socket</tt>, that is the buffer size used by the platform
  1265      * for this {@code Socket}, that is the buffer size used by the platform
  1262      * for input on this <tt>Socket</tt>.
  1266      * for input on this {@code Socket}.
  1263      *
  1267      *
  1264      * @return the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF}
  1268      * @return the value of the {@link SocketOptions#SO_RCVBUF SO_RCVBUF}
  1265      *         option for this <tt>Socket</tt>.
  1269      *         option for this {@code Socket}.
  1266      * @exception SocketException if there is an error
  1270      * @exception SocketException if there is an error
  1267      * in the underlying protocol, such as a TCP error.
  1271      * in the underlying protocol, such as a TCP error.
  1268      * @see #setReceiveBufferSize(int)
  1272      * @see #setReceiveBufferSize(int)
  1269      * @since 1.2
  1273      * @since 1.2
  1270      */
  1274      */
  1296     }
  1300     }
  1297 
  1301 
  1298     /**
  1302     /**
  1299      * Tests if {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE} is enabled.
  1303      * Tests if {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE} is enabled.
  1300      *
  1304      *
  1301      * @return a <code>boolean</code> indicating whether or not
  1305      * @return a {@code boolean} indicating whether or not
  1302      *         {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE} is enabled.
  1306      *         {@link SocketOptions#SO_KEEPALIVE SO_KEEPALIVE} is enabled.
  1303      * @exception SocketException if there is an error
  1307      * @exception SocketException if there is an error
  1304      * in the underlying protocol, such as a TCP error.
  1308      * in the underlying protocol, such as a TCP error.
  1305      * @since   1.3
  1309      * @since   1.3
  1306      * @see #setKeepAlive(boolean)
  1310      * @see #setKeepAlive(boolean)
  1319      *
  1323      *
  1320      * <P> The tc <B>must</B> be in the range {@code 0 <= tc <=
  1324      * <P> The tc <B>must</B> be in the range {@code 0 <= tc <=
  1321      * 255} or an IllegalArgumentException will be thrown.
  1325      * 255} or an IllegalArgumentException will be thrown.
  1322      * <p>Notes:
  1326      * <p>Notes:
  1323      * <p>For Internet Protocol v4 the value consists of an
  1327      * <p>For Internet Protocol v4 the value consists of an
  1324      * <code>integer</code>, the least significant 8 bits of which
  1328      * {@code integer}, the least significant 8 bits of which
  1325      * represent the value of the TOS octet in IP packets sent by
  1329      * represent the value of the TOS octet in IP packets sent by
  1326      * the socket.
  1330      * the socket.
  1327      * RFC 1349 defines the TOS values as follows:
  1331      * RFC 1349 defines the TOS values as follows:
  1328      * <p>
  1332      * <p>
  1329      * <UL>
  1333      * <UL>
  1345      * So whether the type-of-service field can be changed after the
  1349      * So whether the type-of-service field can be changed after the
  1346      * TCP connection has been established depends on the implementation
  1350      * TCP connection has been established depends on the implementation
  1347      * in the underlying platform. Applications should not assume that
  1351      * in the underlying platform. Applications should not assume that
  1348      * they can change the TOS field after the connection.
  1352      * they can change the TOS field after the connection.
  1349      * <p>
  1353      * <p>
  1350      * For Internet Protocol v6 <code>tc</code> is the value that
  1354      * For Internet Protocol v6 {@code tc} is the value that
  1351      * would be placed into the sin6_flowinfo field of the IP header.
  1355      * would be placed into the sin6_flowinfo field of the IP header.
  1352      *
  1356      *
  1353      * @param tc        an <code>int</code> value for the bitset.
  1357      * @param tc        an {@code int} value for the bitset.
  1354      * @throws SocketException if there is an error setting the
  1358      * @throws SocketException if there is an error setting the
  1355      * traffic class or type-of-service
  1359      * traffic class or type-of-service
  1356      * @since 1.4
  1360      * @since 1.4
  1357      * @see #getTrafficClass
  1361      * @see #getTrafficClass
  1358      * @see SocketOptions#IP_TOS
  1362      * @see SocketOptions#IP_TOS
  1390      * Enable/disable the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}
  1394      * Enable/disable the {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}
  1391      * socket option.
  1395      * socket option.
  1392      * <p>
  1396      * <p>
  1393      * When a TCP connection is closed the connection may remain
  1397      * When a TCP connection is closed the connection may remain
  1394      * in a timeout state for a period of time after the connection
  1398      * in a timeout state for a period of time after the connection
  1395      * is closed (typically known as the <tt>TIME_WAIT</tt> state
  1399      * is closed (typically known as the {@code TIME_WAIT} state
  1396      * or <tt>2MSL</tt> wait state).
  1400      * or {@code 2MSL} wait state).
  1397      * For applications using a well known socket address or port
  1401      * For applications using a well known socket address or port
  1398      * it may not be possible to bind a socket to the required
  1402      * it may not be possible to bind a socket to the required
  1399      * <tt>SocketAddress</tt> if there is a connection in the
  1403      * {@code SocketAddress} if there is a connection in the
  1400      * timeout state involving the socket address or port.
  1404      * timeout state involving the socket address or port.
  1401      * <p>
  1405      * <p>
  1402      * Enabling {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}
  1406      * Enabling {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR}
  1403      * prior to binding the socket using {@link #bind(SocketAddress)} allows
  1407      * prior to binding the socket using {@link #bind(SocketAddress)} allows
  1404      * the socket to be bound even though a previous connection is in a timeout
  1408      * the socket to be bound even though a previous connection is in a timeout
  1405      * state.
  1409      * state.
  1406      * <p>
  1410      * <p>
  1407      * When a <tt>Socket</tt> is created the initial setting
  1411      * When a {@code Socket} is created the initial setting
  1408      * of {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is disabled.
  1412      * of {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is disabled.
  1409      * <p>
  1413      * <p>
  1410      * The behaviour when {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is
  1414      * The behaviour when {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is
  1411      * enabled or disabled after a socket is bound (See {@link #isBound()})
  1415      * enabled or disabled after a socket is bound (See {@link #isBound()})
  1412      * is not defined.
  1416      * is not defined.
  1428     }
  1432     }
  1429 
  1433 
  1430     /**
  1434     /**
  1431      * Tests if {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled.
  1435      * Tests if {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled.
  1432      *
  1436      *
  1433      * @return a <code>boolean</code> indicating whether or not
  1437      * @return a {@code boolean} indicating whether or not
  1434      *         {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled.
  1438      *         {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled.
  1435      * @exception SocketException if there is an error
  1439      * @exception SocketException if there is an error
  1436      * in the underlying protocol, such as a TCP error.
  1440      * in the underlying protocol, such as a TCP error.
  1437      * @since   1.4
  1441      * @since   1.4
  1438      * @see #setReuseAddress(boolean)
  1442      * @see #setReuseAddress(boolean)
  1534         getImpl().shutdownOutput();
  1538         getImpl().shutdownOutput();
  1535         shutOut = true;
  1539         shutOut = true;
  1536     }
  1540     }
  1537 
  1541 
  1538     /**
  1542     /**
  1539      * Converts this socket to a <code>String</code>.
  1543      * Converts this socket to a {@code String}.
  1540      *
  1544      *
  1541      * @return  a string representation of this socket.
  1545      * @return  a string representation of this socket.
  1542      */
  1546      */
  1543     public String toString() {
  1547     public String toString() {
  1544         try {
  1548         try {
  1553 
  1557 
  1554     /**
  1558     /**
  1555      * Returns the connection state of the socket.
  1559      * Returns the connection state of the socket.
  1556      * <p>
  1560      * <p>
  1557      * Note: Closing a socket doesn't clear its connection state, which means
  1561      * Note: Closing a socket doesn't clear its connection state, which means
  1558      * this method will return <code>true</code> for a closed socket
  1562      * this method will return {@code true} for a closed socket
  1559      * (see {@link #isClosed()}) if it was successfuly connected prior
  1563      * (see {@link #isClosed()}) if it was successfuly connected prior
  1560      * to being closed.
  1564      * to being closed.
  1561      *
  1565      *
  1562      * @return true if the socket was successfuly connected to a server
  1566      * @return true if the socket was successfuly connected to a server
  1563      * @since 1.4
  1567      * @since 1.4
  1569 
  1573 
  1570     /**
  1574     /**
  1571      * Returns the binding state of the socket.
  1575      * Returns the binding state of the socket.
  1572      * <p>
  1576      * <p>
  1573      * Note: Closing a socket doesn't clear its binding state, which means
  1577      * Note: Closing a socket doesn't clear its binding state, which means
  1574      * this method will return <code>true</code> for a closed socket
  1578      * this method will return {@code true} for a closed socket
  1575      * (see {@link #isClosed()}) if it was successfuly bound prior
  1579      * (see {@link #isClosed()}) if it was successfuly bound prior
  1576      * to being closed.
  1580      * to being closed.
  1577      *
  1581      *
  1578      * @return true if the socket was successfuly bound to an address
  1582      * @return true if the socket was successfuly bound to an address
  1579      * @since 1.4
  1583      * @since 1.4
  1627     /**
  1631     /**
  1628      * Sets the client socket implementation factory for the
  1632      * Sets the client socket implementation factory for the
  1629      * application. The factory can be specified only once.
  1633      * application. The factory can be specified only once.
  1630      * <p>
  1634      * <p>
  1631      * When an application creates a new client socket, the socket
  1635      * When an application creates a new client socket, the socket
  1632      * implementation factory's <code>createSocketImpl</code> method is
  1636      * implementation factory's {@code createSocketImpl} method is
  1633      * called to create the actual socket implementation.
  1637      * called to create the actual socket implementation.
  1634      * <p>
  1638      * <p>
  1635      * Passing <code>null</code> to the method is a no-op unless the factory
  1639      * Passing {@code null} to the method is a no-op unless the factory
  1636      * was already set.
  1640      * was already set.
  1637      * <p>If there is a security manager, this method first calls
  1641      * <p>If there is a security manager, this method first calls
  1638      * the security manager's <code>checkSetFactory</code> method
  1642      * the security manager's {@code checkSetFactory} method
  1639      * to ensure the operation is allowed.
  1643      * to ensure the operation is allowed.
  1640      * This could result in a SecurityException.
  1644      * This could result in a SecurityException.
  1641      *
  1645      *
  1642      * @param      fac   the desired factory.
  1646      * @param      fac   the desired factory.
  1643      * @exception  IOException  if an I/O error occurs when setting the
  1647      * @exception  IOException  if an I/O error occurs when setting the
  1644      *               socket factory.
  1648      *               socket factory.
  1645      * @exception  SocketException  if the factory is already defined.
  1649      * @exception  SocketException  if the factory is already defined.
  1646      * @exception  SecurityException  if a security manager exists and its
  1650      * @exception  SecurityException  if a security manager exists and its
  1647      *             <code>checkSetFactory</code> method doesn't allow the operation.
  1651      *             {@code checkSetFactory} method doesn't allow the operation.
  1648      * @see        java.net.SocketImplFactory#createSocketImpl()
  1652      * @see        java.net.SocketImplFactory#createSocketImpl()
  1649      * @see        SecurityManager#checkSetFactory
  1653      * @see        SecurityManager#checkSetFactory
  1650      */
  1654      */
  1651     public static synchronized void setSocketImplFactory(SocketImplFactory fac)
  1655     public static synchronized void setSocketImplFactory(SocketImplFactory fac)
  1652         throws IOException
  1656         throws IOException
  1676      * are irrelevant; in order to choose a protocol the values are simply
  1680      * are irrelevant; in order to choose a protocol the values are simply
  1677      * compared, with larger values indicating stronger preferences. Negative
  1681      * compared, with larger values indicating stronger preferences. Negative
  1678      * values represent a lower priority than positive values. If the
  1682      * values represent a lower priority than positive values. If the
  1679      * application prefers short connection time over both low latency and high
  1683      * application prefers short connection time over both low latency and high
  1680      * bandwidth, for example, then it could invoke this method with the values
  1684      * bandwidth, for example, then it could invoke this method with the values
  1681      * <tt>(1, 0, 0)</tt>.  If the application prefers high bandwidth above low
  1685      * {@code (1, 0, 0)}.  If the application prefers high bandwidth above low
  1682      * latency, and low latency above short connection time, then it could
  1686      * latency, and low latency above short connection time, then it could
  1683      * invoke this method with the values <tt>(0, 1, 2)</tt>.
  1687      * invoke this method with the values {@code (0, 1, 2)}.
  1684      *
  1688      *
  1685      * <p> Invoking this method after this socket has been connected
  1689      * <p> Invoking this method after this socket has been connected
  1686      * will have no effect.
  1690      * will have no effect.
  1687      *
  1691      *
  1688      * @param  connectionTime
  1692      * @param  connectionTime
  1689      *         An <tt>int</tt> expressing the relative importance of a short
  1693      *         An {@code int} expressing the relative importance of a short
  1690      *         connection time
  1694      *         connection time
  1691      *
  1695      *
  1692      * @param  latency
  1696      * @param  latency
  1693      *         An <tt>int</tt> expressing the relative importance of low
  1697      *         An {@code int} expressing the relative importance of low
  1694      *         latency
  1698      *         latency
  1695      *
  1699      *
  1696      * @param  bandwidth
  1700      * @param  bandwidth
  1697      *         An <tt>int</tt> expressing the relative importance of high
  1701      *         An {@code int} expressing the relative importance of high
  1698      *         bandwidth
  1702      *         bandwidth
  1699      *
  1703      *
  1700      * @since 1.5
  1704      * @since 1.5
  1701      */
  1705      */
  1702     public void setPerformancePreferences(int connectionTime,
  1706     public void setPerformancePreferences(int connectionTime,