800 /** 801 * Tests if {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled. 802 * 803 * @return a {@code boolean} indicating whether or not 804 * {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled. 805 * @exception SocketException if there is an error 806 * in the underlying protocol, such as a TCP error. 807 * @since 1.4 808 * @see #setReuseAddress(boolean) 809 */ 810 public boolean getReuseAddress() throws SocketException { 811 if (isClosed()) 812 throw new SocketException("Socket is closed"); 813 return ((Boolean) (getImpl().getOption(SocketOptions.SO_REUSEADDR))).booleanValue(); 814 } 815 816 /** 817 * Returns the implementation address and implementation port of 818 * this socket as a {@code String}. 819 * <p> 820 * If there is a security manager set, its {@code checkConnect} method is 821 * called with the local address and {@code -1} as its arguments to see 822 * if the operation is allowed. If the operation is not allowed, 823 * an {@code InetAddress} representing the 824 * {@link InetAddress#getLoopbackAddress loopback} address is returned as 825 * the implementation address. 826 * 827 * @return a string representation of this socket. 828 */ 829 public String toString() { 830 if (!isBound()) 831 return "ServerSocket[unbound]"; 832 InetAddress in; 833 if (System.getSecurityManager() != null) 834 in = InetAddress.getLoopbackAddress(); 835 else 836 in = impl.getInetAddress(); 837 return "ServerSocket[addr=" + in + 838 ",localport=" + impl.getLocalPort() + "]"; 839 } 840 841 /** 842 * The factory for all server sockets. 843 */ 844 private static volatile SocketImplFactory factory; 845 846 /** 847 * Sets the server socket implementation factory for the 848 * application. The factory can be specified only once. 849 * <p> 850 * When an application creates a new server socket, the socket 851 * implementation factory's {@code createSocketImpl} method is 852 * called to create the actual socket implementation. 853 * <p> 854 * Passing {@code null} to the method is a no-op unless the factory | 800 /** 801 * Tests if {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled. 802 * 803 * @return a {@code boolean} indicating whether or not 804 * {@link SocketOptions#SO_REUSEADDR SO_REUSEADDR} is enabled. 805 * @exception SocketException if there is an error 806 * in the underlying protocol, such as a TCP error. 807 * @since 1.4 808 * @see #setReuseAddress(boolean) 809 */ 810 public boolean getReuseAddress() throws SocketException { 811 if (isClosed()) 812 throw new SocketException("Socket is closed"); 813 return ((Boolean) (getImpl().getOption(SocketOptions.SO_REUSEADDR))).booleanValue(); 814 } 815 816 /** 817 * Returns the implementation address and implementation port of 818 * this socket as a {@code String}. 819 * <p> 820 * If there is a security manager set, and this socket is 821 * {@linkplain #isBound bound}, its {@code checkConnect} method is 822 * called with the local address and {@code -1} as its arguments to see 823 * if the operation is allowed. If the operation is not allowed, 824 * an {@code InetAddress} representing the 825 * {@link InetAddress#getLoopbackAddress loopback} address is returned as 826 * the implementation address. 827 * 828 * @return a string representation of this socket. 829 */ 830 public String toString() { 831 if (!isBound()) 832 return "ServerSocket[unbound]"; 833 InetAddress in; 834 if (System.getSecurityManager() != null) 835 in = getInetAddress(); 836 else 837 in = impl.getInetAddress(); 838 return "ServerSocket[addr=" + in + 839 ",localport=" + impl.getLocalPort() + "]"; 840 } 841 842 /** 843 * The factory for all server sockets. 844 */ 845 private static volatile SocketImplFactory factory; 846 847 /** 848 * Sets the server socket implementation factory for the 849 * application. The factory can be specified only once. 850 * <p> 851 * When an application creates a new server socket, the socket 852 * implementation factory's {@code createSocketImpl} method is 853 * called to create the actual socket implementation. 854 * <p> 855 * Passing {@code null} to the method is a no-op unless the factory |