Skip to main content

SocketException

java.net.SocketException

SocketException is described in the javadoc comments as:

Thrown to indicate that there is an error in the underlying protocol, such as a TCP error.
author: Jonathan Payne version: 1.17, 12/19/03 since: JDK1.0

Where is this exception thrown?

Following, is a list of exception messages cross-referenced to the source code responsible for throwing them. Click on the method link to view the code and see how the exception is thrown.

How is this exception thrown?

The following sub-sections identify where this exception is thrown, and how (or why) the code is throwing the exception.

Any source code quoted in this section is subject to the Java Research License unless stated otherwise.

java.net.ServerSocket.createImpl()

/**
     * Creates the socket implementation.
     * @throws IOException if creation fails
     * @since 1.4
     */
void createImpl() throws SocketException {
    if (impl == null) setImpl();
    try {
        impl.create(true);
        created = true;
    } catch (IOException e) {
        throw new SocketException(e.getMessage());
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.createImpl(boolean)

/**
     * Creates the socket implementation.
     * @param stream a <code>boolean</code> value : <code>true</code> for a TCP socket,
     *       <code>false</code> for UDP.
     * @throws IOException if creation fails
     * @since 1.4
     */
void createImpl(boolean stream) throws SocketException {
    if (impl == null) setImpl();
    try {
        impl.create(stream);
        created = true;
    } catch (IOException e) {
        throw new SocketException(e.getMessage());
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.SocksSocketImpl.connect(SocketAddress, int)

/**
     * Connects the Socks Socket to the specified endpoint. It will first
     * connect to the SOCKS proxy and negotiate the access. If the proxy
     * grants the connections, then the connect is successful and all
     * further traffic will go to the 'real' endpoint.
     * @param endpoint the <code>SocketAddress</code> to connect to.
     * @param timeout  the timeout value in milliseconds
     * @throws IOException if the connection can't be established.
     * @throws SecurityException if there is a security manager and it
     *    doesn't allow the connection
     * @throws  IllegalArgumentException if endpoint is null or a
     *          SocketAddress subclass not supported by this socket
     */
protected void connect(SocketAddress endpoint, int timeout) throws IOException {
    SecurityManager security = System.getSecurityManager();
    if (endpoint == null || !(endpoint instanceof InetSocketAddress)) throw new IllegalArgumentException('Unsupported address type');
    InetSocketAddress epoint = (InetSocketAddress) endpoint;
    if (security != null) {
        if (epoint.isUnresolved()) security.checkConnect(epoint.getHostName(), epoint.getPort()); else security.checkConnect(epoint.getAddress().getHostAddress(), epoint.getPort());
    }
    if (server == null) {
        ProxySelector sel = (ProxySelector) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

            public Object run() {
                return ProxySelector.getDefault();
            }
        });
        if (sel == null) {
            super.connect(epoint, timeout);
            return;
        }
        URI uri = null;
        String host = epoint.getHostString();
        if (epoint.getAddress() instanceof Inet6Address && (!host.startsWith('[')) && (host.indexOf(':') >= 0)) {
            host = '[' + host + ']';
        }
        try {
            uri = new URI('socket://' + ParseUtil.encodePath(host) + ':' + epoint.getPort());
        } catch (URISyntaxException e) {
            assert false : e;
        }
        Proxy p = null;
        IOException savedExc = null;
        java.util.Iterator<Proxy> iProxy = null;
        iProxy = sel.select(uri).iterator();
        if (iProxy == null || !(iProxy.hasNext())) {
            super.connect(epoint, timeout);
            return;
        }
        while (iProxy.hasNext()) {
            p = iProxy.next();
            if (p == null || p == Proxy.NO_PROXY) {
                super.connect(epoint, timeout);
                return;
            }
            if (p.type() != Proxy.Type.SOCKS) throw new SocketException('Unknown proxy type : ' + p.type());
            if (!(p.address() instanceof InetSocketAddress)) throw new SocketException('Unknow address type for proxy: ' + p);
            server = ((InetSocketAddress) p.address()).getHostString();
            port = ((InetSocketAddress) p.address()).getPort();
            try {
                privilegedConnect(server, port, timeout);
                break;
            } catch (IOException e) {
                sel.connectFailed(uri, p.address(), e);
                server = null;
                port = -1;
                savedExc = e;
            }
        }
        if (server == null) {
            throw new SocketException('Can't connect to SOCKS proxy:' + savedExc.getMessage());
        }
    } else {
        try {
            privilegedConnect(server, port, timeout);
        } catch (IOException e) {
            throw new SocketException(e.getMessage());
        }
    }
    BufferedOutputStream out = new BufferedOutputStream(cmdOut, 512);
    InputStream in = cmdIn;
    if (useV4) {
        if (epoint.isUnresolved()) throw new UnknownHostException(epoint.toString());
        connectV4(in, out, epoint);
        return;
    }
    out.write(PROTO_VERS);
    out.write(2);
    out.write(NO_AUTH);
    out.write(USER_PASSW);
    out.flush();
    byte[] data = new byte[2];
    int i = readSocksReply(in, data);
    if (i != 2 || ((int) data[0]) != PROTO_VERS) {
        if (epoint.isUnresolved()) throw new UnknownHostException(epoint.toString());
        connectV4(in, out, epoint);
        return;
    }
    if (((int) data[1]) == NO_METHODS) throw new SocketException('SOCKS : No acceptable methods');
    if (!authenticate(data[1], in, out)) {
        throw new SocketException('SOCKS : authentication failed');
    }
    out.write(PROTO_VERS);
    out.write(CONNECT);
    out.write(0);
    if (epoint.isUnresolved()) {
        out.write(DOMAIN_NAME);
        out.write(epoint.getHostName().length());
        try {
            out.write(epoint.getHostName().getBytes('ISO-8859-1'));
        } catch (java.io.UnsupportedEncodingException uee) {
            assert false;
        }
        out.write((epoint.getPort() >> 8) & 0xff);
        out.write((epoint.getPort() >> 0) & 0xff);
    } else if (epoint.getAddress() instanceof Inet6Address) {
        out.write(IPV6);
        out.write(epoint.getAddress().getAddress());
        out.write((epoint.getPort() >> 8) & 0xff);
        out.write((epoint.getPort() >> 0) & 0xff);
    } else {
        out.write(IPV4);
        out.write(epoint.getAddress().getAddress());
        out.write((epoint.getPort() >> 8) & 0xff);
        out.write((epoint.getPort() >> 0) & 0xff);
    }
    out.flush();
    data = new byte[4];
    i = readSocksReply(in, data);
    if (i != 4) throw new SocketException('Reply from SOCKS server has bad length');
    SocketException ex = null;
    int nport, len;
    byte[] addr;
    switch(data[1]) {
        case REQUEST_OK:
            switch(data[3]) {
                case IPV4:
                    addr = new byte[4];
                    i = readSocksReply(in, addr);
                    if (i != 4) throw new SocketException('Reply from SOCKS server badly formatted');
                    data = new byte[2];
                    i = readSocksReply(in, data);
                    if (i != 2) throw new SocketException('Reply from SOCKS server badly formatted');
                    nport = ((int) data[0] & 0xff) << 8;
                    nport += ((int) data[1] & 0xff);
                    break;
                case DOMAIN_NAME:
                    len = data[1];
                    byte[] host = new byte[len];
                    i = readSocksReply(in, host);
                    if (i != len) throw new SocketException('Reply from SOCKS server badly formatted');
                    data = new byte[2];
                    i = readSocksReply(in, data);
                    if (i != 2) throw new SocketException('Reply from SOCKS server badly formatted');
                    nport = ((int) data[0] & 0xff) << 8;
                    nport += ((int) data[1] & 0xff);
                    break;
                case IPV6:
                    len = data[1];
                    addr = new byte[len];
                    i = readSocksReply(in, addr);
                    if (i != len) throw new SocketException('Reply from SOCKS server badly formatted');
                    data = new byte[2];
                    i = readSocksReply(in, data);
                    if (i != 2) throw new SocketException('Reply from SOCKS server badly formatted');
                    nport = ((int) data[0] & 0xff) << 8;
                    nport += ((int) data[1] & 0xff);
                    break;
                default:
                    ex = new SocketException('Reply from SOCKS server contains wrong code');
                    break;
            }
            break;
        case GENERAL_FAILURE:
            ex = new SocketException('SOCKS server general failure');
            break;
        case NOT_ALLOWED:
            ex = new SocketException('SOCKS: Connection not allowed by ruleset');
            break;
        case NET_UNREACHABLE:
            ex = new SocketException('SOCKS: Network unreachable');
            break;
        case HOST_UNREACHABLE:
            ex = new SocketException('SOCKS: Host unreachable');
            break;
        case CONN_REFUSED:
            ex = new SocketException('SOCKS: Connection refused');
            break;
        case TTL_EXPIRED:
            ex = new SocketException('SOCKS: TTL expired');
            break;
        case CMD_NOT_SUPPORTED:
            ex = new SocketException('SOCKS: Command not supported');
            break;
        case ADDR_TYPE_NOT_SUP:
            ex = new SocketException('SOCKS: address type not supported');
            break;
    }
    if (ex != null) {
        in.close();
        out.close();
        throw ex;
    }
    external_address = epoint;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.SocksSocketImpl.socksBind(InetSocketAddress)

/**
     * Sends the Bind request to the SOCKS proxy. In the SOCKS protocol, bind
     * means 'accept incoming connection from', so the SocketAddress is the
     * the one of the host we do accept connection from.
     * @param      addr   the Socket address of the remote host.
     * @exception  IOException  if an I/O error occurs when binding this socket.
     */
protected synchronized void socksBind(InetSocketAddress saddr) throws IOException {
    if (socket != null) {
        return;
    }
    if (server == null) {
        ProxySelector sel = (ProxySelector) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

            public Object run() {
                return ProxySelector.getDefault();
            }
        });
        if (sel == null) {
            return;
        }
        URI uri = null;
        String host = saddr.getHostString();
        if (saddr.getAddress() instanceof Inet6Address && (!host.startsWith('[')) && (host.indexOf(':') >= 0)) {
            host = '[' + host + ']';
        }
        try {
            uri = new URI('serversocket://' + ParseUtil.encodePath(host) + ':' + saddr.getPort());
        } catch (URISyntaxException e) {
            assert false : e;
        }
        Proxy p = null;
        Exception savedExc = null;
        java.util.Iterator<Proxy> iProxy = null;
        iProxy = sel.select(uri).iterator();
        if (iProxy == null || !(iProxy.hasNext())) {
            return;
        }
        while (iProxy.hasNext()) {
            p = iProxy.next();
            if (p == null || p == Proxy.NO_PROXY) {
                return;
            }
            if (p.type() != Proxy.Type.SOCKS) throw new SocketException('Unknown proxy type : ' + p.type());
            if (!(p.address() instanceof InetSocketAddress)) throw new SocketException('Unknow address type for proxy: ' + p);
            server = ((InetSocketAddress) p.address()).getHostString();
            port = ((InetSocketAddress) p.address()).getPort();
            try {
                AccessController.doPrivileged(new PrivilegedExceptionAction() {

                    public Object run() throws Exception {
                        cmdsock = new Socket(new PlainSocketImpl());
                        cmdsock.connect(new InetSocketAddress(server, port));
                        cmdIn = cmdsock.getInputStream();
                        cmdOut = cmdsock.getOutputStream();
                        return null;
                    }
                });
            } catch (Exception e) {
                sel.connectFailed(uri, p.address(), new SocketException(e.getMessage()));
                server = null;
                port = -1;
                cmdsock = null;
                savedExc = e;
            }
        }
        if (server == null || cmdsock == null) {
            throw new SocketException('Can't connect to SOCKS proxy:' + savedExc.getMessage());
        }
    } else {
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction() {

                public Object run() throws Exception {
                    cmdsock = new Socket(new PlainSocketImpl());
                    cmdsock.connect(new InetSocketAddress(server, port));
                    cmdIn = cmdsock.getInputStream();
                    cmdOut = cmdsock.getOutputStream();
                    return null;
                }
            });
        } catch (Exception e) {
            throw new SocketException(e.getMessage());
        }
    }
    BufferedOutputStream out = new BufferedOutputStream(cmdOut, 512);
    InputStream in = cmdIn;
    if (useV4) {
        bindV4(in, out, saddr.getAddress(), saddr.getPort());
        return;
    }
    out.write(PROTO_VERS);
    out.write(2);
    out.write(NO_AUTH);
    out.write(USER_PASSW);
    out.flush();
    byte[] data = new byte[2];
    int i = readSocksReply(in, data);
    if (i != 2 || ((int) data[0]) != PROTO_VERS) {
        bindV4(in, out, saddr.getAddress(), saddr.getPort());
        return;
    }
    if (((int) data[1]) == NO_METHODS) throw new SocketException('SOCKS : No acceptable methods');
    if (!authenticate(data[1], in, out)) {
        throw new SocketException('SOCKS : authentication failed');
    }
    out.write(PROTO_VERS);
    out.write(BIND);
    out.write(0);
    int lport = saddr.getPort();
    if (saddr.isUnresolved()) {
        out.write(DOMAIN_NAME);
        out.write(saddr.getHostName().length());
        try {
            out.write(saddr.getHostName().getBytes('ISO-8859-1'));
        } catch (java.io.UnsupportedEncodingException uee) {
            assert false;
        }
        out.write((lport >> 8) & 0xff);
        out.write((lport >> 0) & 0xff);
    } else if (saddr.getAddress() instanceof Inet4Address) {
        byte[] addr1 = saddr.getAddress().getAddress();
        out.write(IPV4);
        out.write(addr1);
        out.write((lport >> 8) & 0xff);
        out.write((lport >> 0) & 0xff);
        out.flush();
    } else if (saddr.getAddress() instanceof Inet6Address) {
        byte[] addr1 = saddr.getAddress().getAddress();
        out.write(IPV6);
        out.write(addr1);
        out.write((lport >> 8) & 0xff);
        out.write((lport >> 0) & 0xff);
        out.flush();
    } else {
        cmdsock.close();
        throw new SocketException('unsupported address type : ' + saddr);
    }
    data = new byte[4];
    i = readSocksReply(in, data);
    SocketException ex = null;
    int len, nport;
    byte[] addr;
    switch(data[1]) {
        case REQUEST_OK:
            InetSocketAddress real_end = null;
            switch(data[3]) {
                case IPV4:
                    addr = new byte[4];
                    i = readSocksReply(in, addr);
                    if (i != 4) throw new SocketException('Reply from SOCKS server badly formatted');
                    data = new byte[2];
                    i = readSocksReply(in, data);
                    if (i != 2) throw new SocketException('Reply from SOCKS server badly formatted');
                    nport = ((int) data[0] & 0xff) << 8;
                    nport += ((int) data[1] & 0xff);
                    external_address = new InetSocketAddress(new Inet4Address('', addr), nport);
                    break;
                case DOMAIN_NAME:
                    len = data[1];
                    byte[] host = new byte[len];
                    i = readSocksReply(in, host);
                    if (i != len) throw new SocketException('Reply from SOCKS server badly formatted');
                    data = new byte[2];
                    i = readSocksReply(in, data);
                    if (i != 2) throw new SocketException('Reply from SOCKS server badly formatted');
                    nport = ((int) data[0] & 0xff) << 8;
                    nport += ((int) data[1] & 0xff);
                    external_address = new InetSocketAddress(new String(host), nport);
                    break;
                case IPV6:
                    len = data[1];
                    addr = new byte[len];
                    i = readSocksReply(in, addr);
                    if (i != len) throw new SocketException('Reply from SOCKS server badly formatted');
                    data = new byte[2];
                    i = readSocksReply(in, data);
                    if (i != 2) throw new SocketException('Reply from SOCKS server badly formatted');
                    nport = ((int) data[0] & 0xff) << 8;
                    nport += ((int) data[1] & 0xff);
                    external_address = new InetSocketAddress(new Inet6Address('', addr), nport);
                    break;
            }
            break;
        case GENERAL_FAILURE:
            ex = new SocketException('SOCKS server general failure');
            break;
        case NOT_ALLOWED:
            ex = new SocketException('SOCKS: Bind not allowed by ruleset');
            break;
        case NET_UNREACHABLE:
            ex = new SocketException('SOCKS: Network unreachable');
            break;
        case HOST_UNREACHABLE:
            ex = new SocketException('SOCKS: Host unreachable');
            break;
        case CONN_REFUSED:
            ex = new SocketException('SOCKS: Connection refused');
            break;
        case TTL_EXPIRED:
            ex = new SocketException('SOCKS: TTL expired');
            break;
        case CMD_NOT_SUPPORTED:
            ex = new SocketException('SOCKS: Command not supported');
            break;
        case ADDR_TYPE_NOT_SUP:
            ex = new SocketException('SOCKS: address type not supported');
            break;
    }
    if (ex != null) {
        in.close();
        out.close();
        cmdsock.close();
        cmdsock = null;
        throw ex;
    }
    cmdIn = in;
    cmdOut = out;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.ServerSocket.bind(SocketAddress, int)

/**
     * Binds the <code>ServerSocket</code> to a specific address
     * (IP address and port number).
     * If the address is <code>null</code>, then the system will pick up
     * an ephemeral port and a valid local address to bind the socket.
     * <P>
     * The <code>backlog</code> argument must be a positive
     * value greater than 0. If the value passed if equal or less
     * than 0, then the default value will be assumed.
     * @param endpoint The IP address & port number to bind to.
     * @param backlog  The listen backlog length.
     * @throws IOException if the bind operation fails, or if the socket
     *      is already bound.
     * @throws SecurityException if a <code>SecurityManager</code> is present and
     * its <code>checkListen</code> method doesn't allow the operation.
     * @throws  IllegalArgumentException if endpoint is a
     *          SocketAddress subclass not supported by this socket
     * @since 1.4
     */
public void bind(SocketAddress endpoint, int backlog) throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (!oldImpl && isBound()) throw new SocketException('Already bound');
    if (endpoint == null) endpoint = new InetSocketAddress(0);
    if (!(endpoint instanceof InetSocketAddress)) throw new IllegalArgumentException('Unsupported address type');
    InetSocketAddress epoint = (InetSocketAddress) endpoint;
    if (epoint.isUnresolved()) throw new SocketException('Unresolved address');
    if (backlog < 1) backlog = 50;
    try {
        SecurityManager security = System.getSecurityManager();
        if (security != null) security.checkListen(epoint.getPort());
        getImpl().bind(epoint.getAddress(), epoint.getPort());
        getImpl().listen(backlog);
        bound = true;
    } catch (SecurityException e) {
        bound = false;
        throw e;
    } catch (IOException e) {
        bound = false;
        throw e;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.bind(SocketAddress)

/**
     * Binds the socket to a local address.
     * <P>
     * If the address is <code>null</code>, then the system will pick up
     * an ephemeral port and a valid local address to bind the socket.
     * @param bindpoint the <code>SocketAddress</code> to bind to
     * @throws IOException if the bind operation fails, or if the socket
     *      is already bound.
     * @throws  IllegalArgumentException if bindpoint is a
     *          SocketAddress subclass not supported by this socket
     * @since 1.4
     * @see #isBound
     */
public void bind(SocketAddress bindpoint) throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (!oldImpl && isBound()) throw new SocketException('Already bound');
    if (bindpoint != null && (!(bindpoint instanceof InetSocketAddress))) throw new IllegalArgumentException('Unsupported address type');
    InetSocketAddress epoint = (InetSocketAddress) bindpoint;
    if (epoint != null && epoint.isUnresolved()) throw new SocketException('Unresolved address');
    if (bindpoint == null) getImpl().bind(InetAddress.anyLocalAddress(), 0); else getImpl().bind(epoint.getAddress(), epoint.getPort());
    bound = true;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.PlainSocketImpl.setOption(int, Object)

public void setOption(int opt, Object val) throws SocketException {
    if (isClosedOrPending()) {
        throw new SocketException('Socket Closed');
    }
    boolean on = true;
    switch(opt) {
        case SO_LINGER:
            if (val == null || (!(val instanceof Integer) && !(val instanceof Boolean))) throw new SocketException('Bad parameter for option');
            if (val instanceof Boolean) {
                on = false;
            }
            break;
        case SO_TIMEOUT:
            if (val == null || (!(val instanceof Integer))) throw new SocketException('Bad parameter for SO_TIMEOUT');
            int tmp = ((Integer) val).intValue();
            if (tmp < 0) throw new IllegalArgumentException('timeout < 0');
            timeout = tmp;
            break;
        case IP_TOS:
            if (val == null || !(val instanceof Integer)) {
                throw new SocketException('bad argument for IP_TOS');
            }
            trafficClass = ((Integer) val).intValue();
            break;
        case SO_BINDADDR:
            throw new SocketException('Cannot re-bind socket');
        case TCP_NODELAY:
            if (val == null || !(val instanceof Boolean)) throw new SocketException('bad parameter for TCP_NODELAY');
            on = ((Boolean) val).booleanValue();
            break;
        case SO_SNDBUF:
        case SO_RCVBUF:
            if (val == null || !(val instanceof Integer) || !(((Integer) val).intValue() > 0)) {
                throw new SocketException('bad parameter for SO_SNDBUF ' + 'or SO_RCVBUF');
            }
            break;
        case SO_KEEPALIVE:
            if (val == null || !(val instanceof Boolean)) throw new SocketException('bad parameter for SO_KEEPALIVE');
            on = ((Boolean) val).booleanValue();
            break;
        case SO_OOBINLINE:
            if (val == null || !(val instanceof Boolean)) throw new SocketException('bad parameter for SO_OOBINLINE');
            on = ((Boolean) val).booleanValue();
            break;
        case SO_REUSEADDR:
            if (val == null || !(val instanceof Boolean)) throw new SocketException('bad parameter for SO_REUSEADDR');
            on = ((Boolean) val).booleanValue();
            break;
        default:
            throw new SocketException('unrecognized TCP option: ' + opt);
    }
    socketSetOption(opt, on, val);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.PlainDatagramSocketImpl.setOption(int, Object)

/**
     * set a value - since we only support (setting) binary options
     * here, o must be a Boolean
     */
public void setOption(int optID, Object o) throws SocketException {
    if (fd == null && fd1 == null) {
        throw new SocketException('Socket Closed');
    }
    switch(optID) {
        case SO_TIMEOUT:
            if (o == null || !(o instanceof Integer)) {
                throw new SocketException('bad argument for SO_TIMEOUT');
            }
            int tmp = ((Integer) o).intValue();
            if (tmp < 0) throw new IllegalArgumentException('timeout < 0');
            timeout = tmp;
            return;
        case IP_TOS:
            if (o == null || !(o instanceof Integer)) {
                throw new SocketException('bad argument for IP_TOS');
            }
            trafficClass = ((Integer) o).intValue();
            break;
        case SO_REUSEADDR:
            if (o == null || !(o instanceof Boolean)) {
                throw new SocketException('bad argument for SO_REUSEADDR');
            }
            break;
        case SO_BROADCAST:
            if (o == null || !(o instanceof Boolean)) {
                throw new SocketException('bad argument for SO_BROADCAST');
            }
            break;
        case SO_BINDADDR:
            throw new SocketException('Cannot re-bind Socket');
        case SO_RCVBUF:
        case SO_SNDBUF:
            if (o == null || !(o instanceof Integer) || ((Integer) o).intValue() < 0) {
                throw new SocketException('bad argument for SO_SNDBUF or ' + 'SO_RCVBUF');
            }
            break;
        case IP_MULTICAST_IF:
            if (o == null || !(o instanceof InetAddress)) throw new SocketException('bad argument for IP_MULTICAST_IF');
            break;
        case IP_MULTICAST_IF2:
            if (o == null || !(o instanceof NetworkInterface)) throw new SocketException('bad argument for IP_MULTICAST_IF2');
            break;
        case IP_MULTICAST_LOOP:
            if (o == null || !(o instanceof Boolean)) throw new SocketException('bad argument for IP_MULTICAST_LOOP');
            break;
        default:
            throw new SocketException('invalid option: ' + optID);
    }
    socketSetOption(optID, o);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.SocketInputStream.read(byte, int, int)

/** 
     * Reads into a byte array <i>b</i> at offset <i>off</i>, 
     * <i>length</i> bytes of data.
     * @param b the buffer into which the data is read
     * @param off the start offset of the data
     * @param len the maximum number of bytes read
     * @return the actual number of bytes read, -1 is
     *          returned when the end of the stream is reached. 
     * @exception IOException If an I/O error has occurred.
     */
public int read(byte b[], int off, int length) throws IOException {
    int n;
    if (eof) {
        return -1;
    }
    if (impl.isConnectionReset()) {
        throw new SocketException('Connection reset');
    }
    if (length <= 0 || off < 0 || off + length > b.length) {
        if (length == 0) {
            return 0;
        }
        throw new ArrayIndexOutOfBoundsException();
    }
    boolean gotReset = false;
    FileDescriptor fd = impl.acquireFD();
    try {
        n = socketRead0(fd, b, off, length, impl.getTimeout());
        if (n > 0) {
            return n;
        }
    } catch (ConnectionResetException rstExc) {
        gotReset = true;
    } finally {
        impl.releaseFD();
    }
    if (gotReset) {
        impl.setConnectionResetPending();
        impl.acquireFD();
        try {
            n = socketRead0(fd, b, off, length, impl.getTimeout());
            if (n > 0) {
                return n;
            }
        } catch (ConnectionResetException rstExc) {
        } finally {
            impl.releaseFD();
        }
    }
    if (impl.isClosedOrPending()) {
        throw new SocketException('Socket closed');
    }
    if (impl.isConnectionResetPending()) {
        impl.setConnectionReset();
    }
    if (impl.isConnectionReset()) {
        throw new SocketException('Connection reset');
    }
    eof = true;
    return -1;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.SocksSocketImpl.readSocksReply(InputStream, byte[])

private int readSocksReply(InputStream in, byte[] data) throws IOException {
    int len = data.length;
    int received = 0;
    for (int attempts = 0; received < len && attempts < 3; attempts++) {
        int count = in.read(data, received, len - received);
        if (count < 0) throw new SocketException('Malformed reply from SOCKS server');
        received += count;
    }
    return received;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.joinGroup(InetAddress)

/**
     * Joins a multicast group. Its behavior may be affected by
     * <code>setInterface</code> or <code>setNetworkInterface</code>.
     * If there is a security manager, this method first
     * calls its <code>checkMulticast</code> method
     * with the <code>mcastaddr</code> argument
     * as its argument.
     * @param mcastaddr is the multicast address to join
     * @exception IOException if there is an error joining
     * or when the address is not a multicast address.
     * @exception  SecurityException  if a security manager exists and its  
     * <code>checkMulticast</code> method doesn't allow the join.
     * @see SecurityManager#checkMulticast(InetAddress)
     */
public void joinGroup(InetAddress mcastaddr) throws IOException {
    if (isClosed()) {
        throw new SocketException('Socket is closed');
    }
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkMulticast(mcastaddr);
    }
    if (!mcastaddr.isMulticastAddress()) {
        throw new SocketException('Not a multicast address');
    }
    getImpl().join(mcastaddr);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.joinGroup(SocketAddress, NetworkInterface)

/**
     * Joins the specified multicast group at the specified interface.
     * If there is a security manager, this method first
     * calls its <code>checkMulticast</code> method
     * with the <code>mcastaddr</code> argument
     * as its argument.
     * @param mcastaddr is the multicast address to join
     * @param netIf specifies the local interface to receive multicast
     *        datagram packets, or <i>null</i> to defer to the interface set by
     *      {@link MulticastSocket#setInterface(InetAddress)} or 
     *      {@link MulticastSocket#setNetworkInterface(NetworkInterface)}
     * @exception IOException if there is an error joining
     * or when the address is not a multicast address.
     * @exception  SecurityException  if a security manager exists and its  
     * <code>checkMulticast</code> method doesn't allow the join.
     * @throws  IllegalArgumentException if mcastaddr is null or is a
     *          SocketAddress subclass not supported by this socket
     * @see SecurityManager#checkMulticast(InetAddress)
     * @since 1.4
     */
public void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress)) throw new IllegalArgumentException('Unsupported address type');
    if (oldImpl) throw new UnsupportedOperationException();
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkMulticast(((InetSocketAddress) mcastaddr).getAddress());
    }
    if (!((InetSocketAddress) mcastaddr).getAddress().isMulticastAddress()) {
        throw new SocketException('Not a multicast address');
    }
    getImpl().joinGroup(mcastaddr, netIf);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.leaveGroup(InetAddress)

/**
     * Leave a multicast group. Its behavior may be affected by
     * <code>setInterface</code> or <code>setNetworkInterface</code>.
     * If there is a security manager, this method first
     * calls its <code>checkMulticast</code> method
     * with the <code>mcastaddr</code> argument
     * as its argument.
     * @param mcastaddr is the multicast address to leave
     * @exception IOException if there is an error leaving
     * or when the address is not a multicast address.
     * @exception  SecurityException  if a security manager exists and its  
     * <code>checkMulticast</code> method doesn't allow the operation.
     * @see SecurityManager#checkMulticast(InetAddress)
     */
public void leaveGroup(InetAddress mcastaddr) throws IOException {
    if (isClosed()) {
        throw new SocketException('Socket is closed');
    }
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkMulticast(mcastaddr);
    }
    if (!mcastaddr.isMulticastAddress()) {
        throw new SocketException('Not a multicast address');
    }
    getImpl().leave(mcastaddr);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.leaveGroup(SocketAddress, NetworkInterface)

/**
     * Leave a multicast group on a specified local interface.
     * If there is a security manager, this method first
     * calls its <code>checkMulticast</code> method
     * with the <code>mcastaddr</code> argument
     * as its argument.
     * @param mcastaddr is the multicast address to leave
     * @param netIf specifies the local interface or <i>null</i> to defer
     *     to the interface set by
     *     {@link MulticastSocket#setInterface(InetAddress)} or 
     *     {@link MulticastSocket#setNetworkInterface(NetworkInterface)}
     * @exception IOException if there is an error leaving
     * or when the address is not a multicast address.
     * @exception  SecurityException  if a security manager exists and its  
     * <code>checkMulticast</code> method doesn't allow the operation.
     * @throws  IllegalArgumentException if mcastaddr is null or is a
     *          SocketAddress subclass not supported by this socket
     * @see SecurityManager#checkMulticast(InetAddress)
     * @since 1.4
     */
public void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (mcastaddr == null || !(mcastaddr instanceof InetSocketAddress)) throw new IllegalArgumentException('Unsupported address type');
    if (oldImpl) throw new UnsupportedOperationException();
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkMulticast(((InetSocketAddress) mcastaddr).getAddress());
    }
    if (!((InetSocketAddress) mcastaddr).getAddress().isMulticastAddress()) {
        throw new SocketException('Not a multicast address');
    }
    getImpl().leaveGroup(mcastaddr, netIf);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.SocksSocketImpl.bindV4(InputStream, OutputStream, InetAddress, int)

private void bindV4(InputStream in, OutputStream out, InetAddress baddr, int lport) throws IOException {
    if (!(baddr instanceof Inet4Address)) {
        throw new SocketException('SOCKS V4 requires IPv4 only addresses');
    }
    super.bind(baddr, lport);
    byte[] addr1 = baddr.getAddress();
    InetAddress naddr = baddr;
    if (naddr.isAnyLocalAddress()) {
        naddr = cmdsock.getLocalAddress();
        addr1 = naddr.getAddress();
    }
    out.write(PROTO_VERS4);
    out.write(BIND);
    out.write((super.getLocalPort() >> 8) & 0xff);
    out.write((super.getLocalPort() >> 0) & 0xff);
    out.write(addr1);
    String userName = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction('user.name'));
    try {
        out.write(userName.getBytes('ISO-8859-1'));
    } catch (java.io.UnsupportedEncodingException uee) {
        assert false;
    }
    out.write(0);
    out.flush();
    byte[] data = new byte[8];
    int n = readSocksReply(in, data);
    if (n != 8) throw new SocketException('Reply from SOCKS server has bad length: ' + n);
    if (data[0] != 0 && data[0] != 4) throw new SocketException('Reply from SOCKS server has bad version');
    SocketException ex = null;
    switch(data[1]) {
        case 90:
            external_address = new InetSocketAddress(baddr, lport);
            break;
        case 91:
            ex = new SocketException('SOCKS request rejected');
            break;
        case 92:
            ex = new SocketException('SOCKS server couldn't reach destination');
            break;
        case 93:
            ex = new SocketException('SOCKS authentication failed');
            break;
        default:
            ex = new SocketException('Reply from SOCKS server contains bad status');
            break;
    }
    if (ex != null) {
        in.close();
        out.close();
        throw ex;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.SocksSocketImpl.connectV4(InputStream, OutputStream, InetSocketAddress)

private void connectV4(InputStream in, OutputStream out, InetSocketAddress endpoint) throws IOException {
    if (!(endpoint.getAddress() instanceof Inet4Address)) {
        throw new SocketException('SOCKS V4 requires IPv4 only addresses');
    }
    out.write(PROTO_VERS4);
    out.write(CONNECT);
    out.write((endpoint.getPort() >> 8) & 0xff);
    out.write((endpoint.getPort() >> 0) & 0xff);
    out.write(endpoint.getAddress().getAddress());
    String userName = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction('user.name'));
    try {
        out.write(userName.getBytes('ISO-8859-1'));
    } catch (java.io.UnsupportedEncodingException uee) {
        assert false;
    }
    out.write(0);
    out.flush();
    byte[] data = new byte[8];
    int n = readSocksReply(in, data);
    if (n != 8) throw new SocketException('Reply from SOCKS server has bad length: ' + n);
    if (data[0] != 0 && data[0] != 4) throw new SocketException('Reply from SOCKS server has bad version');
    SocketException ex = null;
    switch(data[1]) {
        case 90:
            external_address = endpoint;
            break;
        case 91:
            ex = new SocketException('SOCKS request rejected');
            break;
        case 92:
            ex = new SocketException('SOCKS server couldn't reach destination');
            break;
        case 93:
            ex = new SocketException('SOCKS authentication failed');
            break;
        default:
            ex = new SocketException('Reply from SOCKS server contains bad status');
            break;
    }
    if (ex != null) {
        in.close();
        out.close();
        throw ex;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.PlainDatagramSocketImpl.getOption(int)

public Object getOption(int optID) throws SocketException {
    if (fd == null && fd1 == null) {
        throw new SocketException('Socket Closed');
    }
    Object result;
    switch(optID) {
        case SO_TIMEOUT:
            result = new Integer(timeout);
            break;
        case IP_TOS:
            result = socketGetOption(optID);
            if (((Integer) result).intValue() == -1) {
                result = new Integer(trafficClass);
            }
            break;
        case SO_BINDADDR:
            if (fd != null && fd1 != null) {
                return anyLocalBoundAddr;
            }
        case IP_MULTICAST_IF:
        case IP_MULTICAST_IF2:
        case SO_RCVBUF:
        case SO_SNDBUF:
        case IP_MULTICAST_LOOP:
        case SO_REUSEADDR:
        case SO_BROADCAST:
            result = socketGetOption(optID);
            break;
        default:
            throw new SocketException('invalid option: ' + optID);
    }
    return result;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.PlainSocketImpl.getOption(int)

public Object getOption(int opt) throws SocketException {
    if (isClosedOrPending()) {
        throw new SocketException('Socket Closed');
    }
    if (opt == SO_TIMEOUT) {
        return new Integer(timeout);
    }
    int ret = 0;
    switch(opt) {
        case TCP_NODELAY:
            ret = socketGetOption(opt, null);
            return Boolean.valueOf(ret != -1);
        case SO_OOBINLINE:
            ret = socketGetOption(opt, null);
            return Boolean.valueOf(ret != -1);
        case SO_LINGER:
            ret = socketGetOption(opt, null);
            return (ret == -1) ? Boolean.FALSE : (Object) (new Integer(ret));
        case SO_REUSEADDR:
            ret = socketGetOption(opt, null);
            return Boolean.valueOf(ret != -1);
        case SO_BINDADDR:
            if (fd != null && fd1 != null) {
                return anyLocalBoundAddr;
            }
            InetAddressContainer in = new InetAddressContainer();
            ret = socketGetOption(opt, in);
            return in.addr;
        case SO_SNDBUF:
        case SO_RCVBUF:
            ret = socketGetOption(opt, null);
            return new Integer(ret);
        case IP_TOS:
            ret = socketGetOption(opt, null);
            if (ret == -1) {
                return new Integer(trafficClass);
            } else {
                return new Integer(ret);
            }
        case SO_KEEPALIVE:
            ret = socketGetOption(opt, null);
            return Boolean.valueOf(ret != -1);
        default:
            return null;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.SocketOutputStream.socketWrite(byte, int, int)

/**
     * Writes to the socket with appropriate locking of the 
     * FileDescriptor.
     * @param b the data to be written
     * @param off the start offset in the data
     * @param len the number of bytes that are written
     * @exception IOException If an I/O error has occurred.
     */
private void socketWrite(byte b[], int off, int len) throws IOException {
    if (len <= 0 || off < 0 || off + len > b.length) {
        if (len == 0) {
            return;
        }
        throw new ArrayIndexOutOfBoundsException();
    }
    FileDescriptor fd = impl.acquireFD();
    try {
        socketWrite0(fd, b, off, len);
    } catch (SocketException se) {
        if (se instanceof sun.net.ConnectionResetException) {
            impl.setConnectionResetPending();
            se = new SocketException('Connection reset');
        }
        if (impl.isClosedOrPending()) {
            throw new SocketException('Socket closed');
        } else {
            throw se;
        }
    } finally {
        impl.releaseFD();
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.shutdownInput()

/**
     * Places the input stream for this socket at 'end of stream'.
     * Any data sent to the input stream side of the socket is acknowledged
     * and then silently discarded.
     * If you read from a socket input stream after invoking 
     * shutdownInput() on the socket, the stream will return EOF.
     * @exception IOException if an I/O error occurs when shutting down this
     * socket.
     * @since 1.3
     * @see java.net.Socket#shutdownOutput()
     * @see java.net.Socket#close()
     * @see java.net.Socket#setSoLinger(boolean, int)
     * @see #isInputShutdown
     */
public void shutdownInput() throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (!isConnected()) throw new SocketException('Socket is not connected');
    if (isInputShutdown()) throw new SocketException('Socket input is already shutdown');
    getImpl().shutdownInput();
    shutIn = true;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getInputStream()

/**
     * Returns an input stream for this socket.
     *  If this socket has an associated channel then the resulting input
     * stream delegates all of its operations to the channel.  If the channel
     * is in non-blocking mode then the input stream's <tt>read</tt> operations
     * will throw an {@link java.nio.channels.IllegalBlockingModeException}.
     * Under abnormal conditions the underlying connection may be
     * broken by the remote host or the network software (for example
     * a connection reset in the case of TCP connections). When a
     * broken connection is detected by the network software the
     * following applies to the returned input stream :-
     * <ul>
     *   <li>The network software may discard bytes that are buffered
     *   by the socket. Bytes that aren't discarded by the network 
     *   software can be read using {@link java.io.InputStream#read read}.
     *   <li>If there are no bytes buffered on the socket, or all
     *   buffered bytes have been consumed by  
     *   {@link java.io.InputStream#read read}, then all subsequent
     *   calls to {@link java.io.InputStream#read read} will throw an 
     *   {@link java.io.IOException IOException}. 
     *   <li>If there are no bytes buffered on the socket, and the
     *   socket has not been closed using {@link #close close}, then
     *   {@link java.io.InputStream#available available} will
     *   return <code>0</code>.
     * </ul>
     * @return     an input stream for reading bytes from this socket.
     * @exception  IOException  if an I/O error occurs when creating the
     *             input stream, the socket is closed, the socket is
     *             not connected, or the socket input has been shutdown
     *             using {@link #shutdownInput()}
     * @revised 1.4
     * @spec JSR-51
     */
public InputStream getInputStream() throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (!isConnected()) throw new SocketException('Socket is not connected');
    if (isInputShutdown()) throw new SocketException('Socket input is shutdown');
    final Socket s = this;
    InputStream is = null;
    try {
        is = (InputStream) AccessController.doPrivileged(new PrivilegedExceptionAction() {

            public Object run() throws IOException {
                return impl.getInputStream();
            }
        });
    } catch (java.security.PrivilegedActionException e) {
        throw (IOException) e.getException();
    }
    return is;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.bind(SocketAddress)

/**
     * Binds this DatagramSocket to a specific address & port.
     * If the address is <code>null</code>, then the system will pick up
     * an ephemeral port and a valid local address to bind the socket.
     * @param addr The address & port to bind to.
     * @throws SocketException if any error happens during the bind, or if the
     *  socket is already bound.
     * @throws SecurityException  if a security manager exists and its  
     *             <code>checkListen</code> method doesn't allow the operation.
     * @throws IllegalArgumentException if addr is a SocketAddress subclass
     *         not supported by this socket.
     * @since 1.4
     */
public synchronized void bind(SocketAddress addr) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (isBound()) throw new SocketException('already bound');
    if (addr == null) addr = new InetSocketAddress(0);
    if (!(addr instanceof InetSocketAddress)) throw new IllegalArgumentException('Unsupported address type!');
    InetSocketAddress epoint = (InetSocketAddress) addr;
    if (epoint.isUnresolved()) throw new SocketException('Unresolved address');
    SecurityManager sec = System.getSecurityManager();
    if (sec != null) {
        sec.checkListen(epoint.getPort());
    }
    try {
        getImpl().bind(epoint.getPort(), epoint.getAddress());
    } catch (SocketException e) {
        getImpl().close();
        throw e;
    }
    bound = true;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.getBroadcast()

/**
     * Tests if SO_BROADCAST is enabled.
     * @return a <code>boolean</code> indicating whether or not SO_BROADCAST is enabled.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as an UDP error.
     * @since 1.4
     * @see #setBroadcast(boolean)
     */
public synchronized boolean getBroadcast() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    return ((Boolean) (getImpl().getOption(SocketOptions.SO_BROADCAST))).booleanValue();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.getReceiveBufferSize()

/**
     * Get value of the SO_RCVBUF option for this <tt>DatagramSocket</tt>, that is the
     * buffer size used by the platform for input on this <tt>DatagramSocket</tt>.
     * @return the value of the SO_RCVBUF option for this <tt>DatagramSocket</tt>
     * @exception SocketException if there is an error in the underlying protocol, such as an UDP error.
     * @see #setReceiveBufferSize(int)
     */
public synchronized int getReceiveBufferSize() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    int result = 0;
    Object o = getImpl().getOption(SocketOptions.SO_RCVBUF);
    if (o instanceof Integer) {
        result = ((Integer) o).intValue();
    }
    return result;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.getReuseAddress()

/**
     * Tests if SO_REUSEADDR is enabled.
     * @return a <code>boolean</code> indicating whether or not SO_REUSEADDR is enabled.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as an UDP error. 
     * @since   1.4
     * @see #setReuseAddress(boolean)
     */
public synchronized boolean getReuseAddress() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    Object o = getImpl().getOption(SocketOptions.SO_REUSEADDR);
    return ((Boolean) o).booleanValue();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.getSendBufferSize()

/**
     * Get value of the SO_SNDBUF option for this <tt>DatagramSocket</tt>, that is the
     * buffer size used by the platform for output on this <tt>DatagramSocket</tt>.
     * @return the value of the SO_SNDBUF option for this <tt>DatagramSocket</tt>
     * @exception SocketException if there is an error in 
     * the underlying protocol, such as an UDP error.
     * @see #setSendBufferSize
     */
public synchronized int getSendBufferSize() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    int result = 0;
    Object o = getImpl().getOption(SocketOptions.SO_SNDBUF);
    if (o instanceof Integer) {
        result = ((Integer) o).intValue();
    }
    return result;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.getSoTimeout()

/**
     * Retrive setting for SO_TIMEOUT.  0 returns implies that the
     * option is disabled (i.e., timeout of infinity).
     * @return the setting for SO_TIMEOUT
     * @throws SocketException if there is an error in the underlying protocol, such as an UDP error.
     * @since   JDK1.1
     * @see #setSoTimeout(int)
     */
public synchronized int getSoTimeout() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (getImpl() == null) return 0;
    Object o = getImpl().getOption(SocketOptions.SO_TIMEOUT);
    if (o instanceof Integer) {
        return ((Integer) o).intValue();
    } else {
        return 0;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.getTrafficClass()

/**
     * Gets traffic class or type-of-service in the IP datagram 
     * header for packets sent from this DatagramSocket.
     * As the underlying network implementation may ignore the
     * traffic class or type-of-service set using {@link #setTrafficClass(int)}
     * this method may return a different value than was previously
     * set using the {@link #setTrafficClass(int)} method on this 
     * DatagramSocket.
     * @return the traffic class or type-of-service already set
     * @throws SocketException if there is an error obtaining the
     * traffic class or type-of-service value.
     * @since 1.4
     * @see #setTrafficClass(int)
     */
public synchronized int getTrafficClass() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    return ((Integer) (getImpl().getOption(SocketOptions.IP_TOS))).intValue();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.send(DatagramPacket)

/**
     * 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.
     * If there is a security manager, and the socket is not currently
     * connected to a remote address, this method first performs some
     * security checks. First, if <code>p.getAddress().isMulticastAddress()</code>
     * is true, this method calls the
     * security manager's <code>checkMulticast</code> method
     * with <code>p.getAddress()</code> as its argument.
     * If the evaluation of that expression is false,
     * this method instead calls the security manager's 
     * <code>checkConnect</code> method with arguments
     * <code>p.getAddress().getHostAddress()</code> and
     * <code>p.getPort()</code>. Each call to a security manager method
     * could result in a SecurityException if the operation is not allowed.
     * @param      p   the <code>DatagramPacket</code> to be sent.
     * @exception  IOException  if an I/O error occurs.
     * @exception  SecurityException  if a security manager exists and its  
     *             <code>checkMulticast</code> or <code>checkConnect</code> 
     *             method doesn't allow the send.
     * @exception  PortUnreachableException may be thrown if the socket is connected
     *             to a currently unreachable destination. Note, there is no 
     *      guarantee that the exception will be thrown.
     * @exception  java.nio.channels.IllegalBlockingModeException
     *             if this socket has an associated channel,
     *             and the channel is in non-blocking mode.
     * @see        java.net.DatagramPacket
     * @see        SecurityManager#checkMulticast(InetAddress)
     * @see        SecurityManager#checkConnect
     * @revised 1.4
     * @spec JSR-51
     */
public void send(DatagramPacket p) throws IOException {
    InetAddress packetAddress = null;
    synchronized (p) {
        if (isClosed()) throw new SocketException('Socket is closed');
        if (connectState == ST_NOT_CONNECTED) {
            SecurityManager security = System.getSecurityManager();
            if (security != null) {
                if (p.getAddress().isMulticastAddress()) {
                    security.checkMulticast(p.getAddress());
                } else {
                    security.checkConnect(p.getAddress().getHostAddress(), p.getPort());
                }
            }
        } else {
            packetAddress = p.getAddress();
            if (packetAddress == null) {
                p.setAddress(connectedAddress);
                p.setPort(connectedPort);
            } else if ((!packetAddress.equals(connectedAddress)) || p.getPort() != connectedPort) {
                throw new IllegalArgumentException('connected address ' + 'and packet address' + ' differ');
            }
        }
        if (!isBound()) bind(new InetSocketAddress(0));
        getImpl().send(p);
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.setBroadcast(boolean)

/**
     * Enable/disable SO_BROADCAST.
     * @param on     whether or not to have broadcast turned on.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as an UDP error.
     * @since 1.4
     * @see #getBroadcast()
     */
public synchronized void setBroadcast(boolean on) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_BROADCAST, Boolean.valueOf(on));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.setReceiveBufferSize(int)

/**
     * Sets the SO_RCVBUF option to the specified value for this
     * <tt>DatagramSocket</tt>. The SO_RCVBUF option is used by the
     * the network implementation as a hint to size the underlying
     * network I/O buffers. The SO_RCVBUF setting may also be used
     * by the network implementation to determine the maximum size
     * of the packet that can be received on this socket.
     * Because SO_RCVBUF is a hint, applications that want to
     * verify what size the buffers were set to should call
     * {@link #getReceiveBufferSize()}.
     * Increasing SO_RCVBUF may allow the network implementation
     * to buffer multiple packets when packets arrive faster than
     * are being received using {@link #receive(DatagramPacket)}.
     * Note: It is implementation specific if a packet larger
     * than SO_RCVBUF can be received.
     * @param size the size to which to set the receive buffer
     * size. This value must be greater than 0.
     * @exception SocketException if there is an error in 
     * the underlying protocol, such as an UDP error.
     * @exception IllegalArgumentException if the value is 0 or is
     * negative.
     * @see #getReceiveBufferSize()
     */
public synchronized void setReceiveBufferSize(int size) throws SocketException {
    if (size <= 0) {
        throw new IllegalArgumentException('invalid receive size');
    }
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.setReuseAddress(boolean)

/**
     * Enable/disable the SO_REUSEADDR socket option.
     * For UDP sockets it may be necessary to bind more than one
     * socket to the same socket address. This is typically for the
     * purpose of receiving multicast packets
     * (See {@link java.net.MulticastSocket}). The
     * <tt>SO_REUSEADDR</tt> socket option allows multiple
     * sockets to be bound to the same socket address if the
     * <tt>SO_REUSEADDR</tt> socket option is enabled prior
     * to binding the socket using {@link #bind(SocketAddress)}.
     * When a <tt>DatagramSocket</tt> is created the initial setting
     * of <tt>SO_REUSEADDR</tt> is disabled.
     * The behaviour when <tt>SO_REUSEADDR</tt> is enabled or
     * disabled after a socket is bound (See {@link #isBound()})
     * is not defined.
     * @param on  whether to enable or disable the 
     * @exception SocketException if an error occurs enabling or
     *            disabling the <tt>SO_RESUEADDR</tt> socket option,
     *       or the socket is closed.
     * @since 1.4
     * @see #getReuseAddress()     
     * @see #bind(SocketAddress)     
     * @see #isBound()
     * @see #isClosed()
     */
public synchronized void setReuseAddress(boolean on) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (oldImpl) getImpl().setOption(SocketOptions.SO_REUSEADDR, new Integer(on ? -1 : 0)); else getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.setSendBufferSize(int)

/**
     * Sets the SO_SNDBUF option to the specified value for this
     * <tt>DatagramSocket</tt>. The SO_SNDBUF option is used by the 
     * network implementation as a hint to size the underlying
     * network I/O buffers. The SO_SNDBUF setting may also be used 
     * by the network implementation to determine the maximum size
     * of the packet that can be sent on this socket.
     * As SO_SNDBUF is a hint, applications that want to verify
     * what size the buffer is should call {@link #getSendBufferSize()}.
     * Increasing the buffer size may allow multiple outgoing packets 
     * to be queued by the network implementation when the send rate
     * is high. 
     * Note: If {@link #send(DatagramPacket)} is used to send a 
     * <code>DatagramPacket</code> that is larger than the setting
     * of SO_SNDBUF then it is implementation specific if the
     * packet is sent or discarded.
     * @param size the size to which to set the send buffer
     * size. This value must be greater than 0.
     * @exception SocketException if there is an error 
     * in the underlying protocol, such as an UDP error.
     * @exception IllegalArgumentException if the value is 0 or is
     * negative.
     * @see #getSendBufferSize()
     */
public synchronized void setSendBufferSize(int size) throws SocketException {
    if (!(size > 0)) {
        throw new IllegalArgumentException('negative send size');
    }
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.setSoTimeout(int)

/** 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.net.SocketTimeoutException</B> is raised, though the
     *  DatagramSocket 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.
     * @param timeout the specified timeout in milliseconds.
     * @throws SocketException if there is an error in the underlying protocol, such as an UDP error. 
     * @since   JDK1.1
     * @see #getSoTimeout()
     */
public synchronized void setSoTimeout(int timeout) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.setTrafficClass(int)

/**
     * Sets traffic class or type-of-service octet in the IP
     * datagram header for datagrams sent from this DatagramSocket.
     * As the underlying network implementation may ignore this
     * value applications should consider it a hint.
     * <P> The tc <B>must</B> be in the range <code> 0 <= tc <=
     * 255</code> or an IllegalArgumentException will be thrown.
     * Notes:
     *  for Internet Protocol v4 the value consists of an octet
     * with precedence and TOS fields as detailed in RFC 1349. The
     * TOS field is bitset created by bitwise-or'ing values such
     * the following :-
     * <UL>
     * <LI><CODE>IPTOS_LOWCOST (0x02)</CODE></LI>
     * <LI><CODE>IPTOS_RELIABILITY (0x04)</CODE></LI>
     * <LI><CODE>IPTOS_THROUGHPUT (0x08)</CODE></LI>
     * <LI><CODE>IPTOS_LOWDELAY (0x10)</CODE></LI>
     * </UL>
     * The last low order bit is always ignored as this
     * corresponds to the MBZ (must be zero) bit.
     * Setting bits in the precedence field may result in a 
     * SocketException indicating that the operation is not
     * permitted.
     * for Internet Protocol v6 <code>tc</code> is the value that 
     * would be placed into the sin6_flowinfo field of the IP header.
     * @param tc an <code>int</code> value for the bitset.
     * @throws SocketException if there is an error setting the
     * traffic class or type-of-service 
     * @since 1.4
     * @see #getTrafficClass
     */
public synchronized void setTrafficClass(int tc) throws SocketException {
    if (tc < 0 || tc > 255) throw new IllegalArgumentException('tc is not in range 0 -- 255');
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.getInterface()

/**
     * Retrieve the address of the network interface used for
     * multicast packets.
     * @return An <code>InetAddress</code> representing
     *  the address of the network interface used for 
     *  multicast packets.
     * @exception SocketException if there is an error in 
     * the underlying protocol, such as a TCP error.
     * @see #setInterface(java.net.InetAddress)
     */
public InetAddress getInterface() throws SocketException {
    if (isClosed()) {
        throw new SocketException('Socket is closed');
    }
    synchronized (infLock) {
        InetAddress ia = (InetAddress) getImpl().getOption(SocketOptions.IP_MULTICAST_IF);
        if (infAddress == null) {
            return ia;
        }
        if (ia.equals(infAddress)) {
            return ia;
        }
        try {
            NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
            Enumeration addrs = ni.getInetAddresses();
            while (addrs.hasMoreElements()) {
                InetAddress addr = (InetAddress) (addrs.nextElement());
                if (addr.equals(infAddress)) {
                    return infAddress;
                }
            }
            infAddress = null;
            return ia;
        } catch (Exception e) {
            return ia;
        }
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.getTTL()

/**
     * Get the default time-to-live for multicast packets sent out on
     * the socket.
     * @exception IOException if an I/O exception occurs
     * while getting the default time-to-live value
     * @return the default time-to-live value
     * @deprecated use the getTimeToLive method instead, which returns
     * an <b>int</b> instead of a <b>byte</b>.
     * @see #setTTL(byte)
     */
@Deprecated
public byte getTTL() throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    return getImpl().getTTL();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.getTimeToLive()

/**
     * Get the default time-to-live for multicast packets sent out on
     * the socket.
     * @exception IOException if an I/O exception occurs while
     * getting the default time-to-live value
     * @return the default time-to-live value
     * @see #setTimeToLive(int)
     */
public int getTimeToLive() throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    return getImpl().getTimeToLive();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.send(DatagramPacket, byte)

/**
     * Sends a datagram packet to the destination, with a TTL (time-
     * to-live) other than the default for the socket.  This method
     * need only be used in instances where a particular TTL is desired;
     * otherwise it is preferable to set a TTL once on the socket, and
     * use that default TTL for all packets.  This method does <B>not
     * </B> alter the default TTL for the socket. Its behavior may be
     * affected by <code>setInterface</code>.
     * If there is a security manager, this method first performs some
     * security checks. First, if <code>p.getAddress().isMulticastAddress()</code>
     * is true, this method calls the
     * security manager's <code>checkMulticast</code> method
     * with <code>p.getAddress()</code> and <code>ttl</code> as its arguments.
     * If the evaluation of that expression is false,
     * this method instead calls the security manager's 
     * <code>checkConnect</code> method with arguments
     * <code>p.getAddress().getHostAddress()</code> and
     * <code>p.getPort()</code>. Each call to a security manager method
     * could result in a SecurityException if the operation is not allowed.
     * @param p is the packet to be sent. The packet should contain
     * the destination multicast ip address and the data to be sent.
     * One does not need to be the member of the group to send
     * packets to a destination multicast address.
     * @param ttl optional time to live for multicast packet.
     * default ttl is 1.
     * @exception IOException is raised if an error occurs i.e
     * error while setting ttl.
     * @exception  SecurityException  if a security manager exists and its  
     *             <code>checkMulticast</code> or <code>checkConnect</code> 
     *             method doesn't allow the send.
     * @deprecated Use the following code or its equivalent instead:
     * ......
     * int ttl = mcastSocket.getTimeToLive();
     *  mcastSocket.setTimeToLive(newttl);
     * mcastSocket.send(p);
     * mcastSocket.setTimeToLive(ttl);
     * ......
     * @see DatagramSocket#send
     * @see DatagramSocket#receive
     * @see SecurityManager#checkMulticast(java.net.InetAddress, byte)
     * @see SecurityManager#checkConnect
     */
@Deprecated
public void send(DatagramPacket p, byte ttl) throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    synchronized (ttlLock) {
        synchronized (p) {
            if (connectState == ST_NOT_CONNECTED) {
                SecurityManager security = System.getSecurityManager();
                if (security != null) {
                    if (p.getAddress().isMulticastAddress()) {
                        security.checkMulticast(p.getAddress(), ttl);
                    } else {
                        security.checkConnect(p.getAddress().getHostAddress(), p.getPort());
                    }
                }
            } else {
                InetAddress packetAddress = null;
                packetAddress = p.getAddress();
                if (packetAddress == null) {
                    p.setAddress(connectedAddress);
                    p.setPort(connectedPort);
                } else if ((!packetAddress.equals(connectedAddress)) || p.getPort() != connectedPort) {
                    throw new SecurityException('connected address and packet address' + ' differ');
                }
            }
            byte dttl = getTTL();
            try {
                if (ttl != dttl) {
                    getImpl().setTTL(ttl);
                }
                getImpl().send(p);
            } finally {
                if (ttl != dttl) {
                    getImpl().setTTL(dttl);
                }
            }
        }
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.setInterface(InetAddress)

/**
     * Set the multicast network interface used by methods
     * whose behavior would be affected by the value of the
     * network interface. Useful for multihomed hosts.
     * @param inf the InetAddress
     * @exception SocketException if there is an error in 
     * the underlying protocol, such as a TCP error. 
     * @see #getInterface()
     */
public void setInterface(InetAddress inf) throws SocketException {
    if (isClosed()) {
        throw new SocketException('Socket is closed');
    }
    synchronized (infLock) {
        getImpl().setOption(SocketOptions.IP_MULTICAST_IF, inf);
        infAddress = inf;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.setTTL(byte)

/**
     * Set the default time-to-live for multicast packets sent out
     * on this <code>MulticastSocket</code> in order to control the 
     * scope of the multicasts.
     * The ttl is an <b>unsigned</b> 8-bit quantity, and so <B>must</B> be
     * in the range <code> 0 <= ttl <= 0xFF </code>.
     * @param ttl the time-to-live
     * @exception IOException if an I/O exception occurs
     * while setting the default time-to-live value
     * @deprecated use the setTimeToLive method instead, which uses
     * <b>int</b> instead of <b>byte</b> as the type for ttl.
     * @see #getTTL()
     */
@Deprecated
public void setTTL(byte ttl) throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setTTL(ttl);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.MulticastSocket.setTimeToLive(int)

/**
     * Set the default time-to-live for multicast packets sent out
     * on this <code>MulticastSocket</code> in order to control the 
     * scope of the multicasts.
     * <P> The ttl <B>must</B> be in the range <code> 0 <= ttl <=
     * 255</code> or an IllegalArgumentException will be thrown.
     * @exception IOException if an I/O exception occurs
     * while setting the default time-to-live value
     * @param ttl the time-to-live
     * @see #getTimeToLive()
     */
public void setTimeToLive(int ttl) throws IOException {
    if (ttl < 0 || ttl > 255) {
        throw new IllegalArgumentException('ttl out of range');
    }
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setTimeToLive(ttl);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.ServerSocket.accept()

/**
     * Listens for a connection to be made to this socket and accepts 
     * it. The method blocks until a connection is made. 
     * A new Socket <code>s</code> is created and, if there 
     * is a security manager, 
     * the security manager's <code>checkAccept</code> method is called
     * with <code>s.getInetAddress().getHostAddress()</code> and
     * <code>s.getPort()</code>
     * as its arguments to ensure the operation is allowed. 
     * This could result in a SecurityException.
     * @exception  IOException  if an I/O error occurs when waiting for a
     *               connection.
     * @exception  SecurityException  if a security manager exists and its  
     *             <code>checkListen</code> method doesn't allow the operation.
     * @exception  SocketTimeoutException if a timeout was previously set with setSoTimeout and
     *             the timeout has been reached.
     * @exception  java.nio.channels.IllegalBlockingModeException
     *             if this socket has an associated channel, the channel is in
     *             non-blocking mode, and there is no connection ready to be
     *             accepted
     * @return the new Socket
     * @see SecurityManager#checkAccept
     * @revised 1.4
     * @spec JSR-51
     */
public Socket accept() throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (!isBound()) throw new SocketException('Socket is not bound yet');
    Socket s = new Socket((SocketImpl) null);
    implAccept(s);
    return s;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.ServerSocket.getReceiveBufferSize()

/**
     * Gets the value of the SO_RCVBUF option for this <tt>ServerSocket</tt>, 
     * that is the proposed buffer size that will be used for Sockets accepted
     * from this <tt>ServerSocket</tt>.
     * Note, the value actually set in the accepted socket is determined by
     * calling {@link Socket#getReceiveBufferSize()}.
     * @return the value of the SO_RCVBUF option for this <tt>Socket</tt>.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @see #setReceiveBufferSize(int)
     * @since 1.4
     */
public synchronized int getReceiveBufferSize() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    int result = 0;
    Object o = getImpl().getOption(SocketOptions.SO_RCVBUF);
    if (o instanceof Integer) {
        result = ((Integer) o).intValue();
    }
    return result;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.ServerSocket.getReuseAddress()

/**
     * Tests if SO_REUSEADDR is enabled.
     * @return a <code>boolean</code> indicating whether or not SO_REUSEADDR is enabled.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @since   1.4
     * @see #setReuseAddress(boolean)
     */
public boolean getReuseAddress() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    return ((Boolean) (getImpl().getOption(SocketOptions.SO_REUSEADDR))).booleanValue();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.ServerSocket.getSoTimeout()

/** 
     * Retrive setting for SO_TIMEOUT.  0 returns implies that the
     * option is disabled (i.e., timeout of infinity).
     * @return the SO_TIMEOUT value
     * @exception IOException if an I/O error occurs
     * @since   JDK1.1
     * @see #setSoTimeout(int)
     */
public synchronized int getSoTimeout() throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    Object o = getImpl().getOption(SocketOptions.SO_TIMEOUT);
    if (o instanceof Integer) {
        return ((Integer) o).intValue();
    } else {
        return 0;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.ServerSocket.setReceiveBufferSize(int)

/**
     * Sets a default proposed value for the SO_RCVBUF option for sockets 
     * accepted from this <tt>ServerSocket</tt>. The value actually set 
     * in the accepted socket must be determined by calling 
     * {@link Socket#getReceiveBufferSize()} after the socket 
     * is returned by {@link #accept()}. 
     * The value of SO_RCVBUF is used both to set the size of the internal
     * socket receive buffer, and to set the size of the TCP receive window
     * that is advertized to the remote peer.
     * It is possible to change the value subsequently, by calling 
     * {@link Socket#setReceiveBufferSize(int)}. However, if the application 
     * wishes to allow a receive window larger than 64K bytes, as defined by RFC1323
     * then the proposed value must be set in the ServerSocket <B>before</B> 
     * it is bound to a local address. This implies, that the ServerSocket must be 
     * created with the no-argument constructor, then setReceiveBufferSize() must 
     * be called and lastly the ServerSocket is bound to an address by calling bind(). 
     * Failure to do this will not cause an error, and the buffer size may be set to the
     * requested value but the TCP receive window in sockets accepted from 
     * this ServerSocket will be no larger than 64K bytes.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @param size the size to which to set the receive buffer
     * size. This value must be greater than 0.
     * @exception IllegalArgumentException if the 
     * value is 0 or is negative.
     * @since 1.4
     * @see #getReceiveBufferSize
     */
public synchronized void setReceiveBufferSize(int size) throws SocketException {
    if (!(size > 0)) {
        throw new IllegalArgumentException('negative receive size');
    }
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.ServerSocket.setReuseAddress(boolean)

/**
     * Enable/disable the SO_REUSEADDR socket option.
     * When a TCP connection is closed the connection may remain
     * in a timeout state for a period of time after the connection
     * is closed (typically known as the <tt>TIME_WAIT</tt> state 
     * or <tt>2MSL</tt> wait state).
     * For applications using a well known socket address or port 
     * it may not be possible to bind a socket to the required
     * <tt>SocketAddress</tt> if there is a connection in the
     * timeout state involving the socket address or port. 
     * Enabling <tt>SO_REUSEADDR</tt> prior to binding the socket
     * using {@link #bind(SocketAddress)} allows the socket to be
     * bound even though a previous connection is in a timeout
     * state.
     * When a <tt>ServerSocket</tt> is created the initial setting
     * of <tt>SO_REUSEADDR</tt> is not defined. Applications can
     * use {@link #getReuseAddress()} to determine the initial 
     * setting of <tt>SO_REUSEADDR</tt>. 
     * The behaviour when <tt>SO_REUSEADDR</tt> is enabled or
     * disabled after a socket is bound (See {@link #isBound()})
     * is not defined.
     * @param on  whether to enable or disable the socket option
     * @exception SocketException if an error occurs enabling or
     *            disabling the <tt>SO_RESUEADDR</tt> socket option,
     *    or the socket is closed.
     * @since 1.4
     * @see #getReuseAddress()     
     * @see #bind(SocketAddress)
     * @see #isBound()
     * @see #isClosed()
     */
public void setReuseAddress(boolean on) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.ServerSocket.setSoTimeout(int)

/**
     * Enable/disable SO_TIMEOUT with the specified timeout, in
     * milliseconds.  With this option set to a non-zero timeout,
     * a call to accept() for this ServerSocket
     * will block for only this amount of time.  If the timeout expires,
     * a <B>java.net.SocketTimeoutException</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.  
     * @param timeout the specified timeout, in milliseconds
     * @exception SocketException if there is an error in 
     * the underlying protocol, such as a TCP error. 
     * @since   JDK1.1
     * @see #getSoTimeout()
     */
public synchronized void setSoTimeout(int timeout) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.connect(SocketAddress, int)

/**
     * Connects this socket to the server with a specified timeout value.
     * A timeout of zero is interpreted as an infinite timeout. The connection
     * will then block until established or an error occurs.
     * @param endpoint the <code>SocketAddress</code>
     * @param timeout  the timeout value to be used in milliseconds.
     * @throws IOException if an error occurs during the connection
     * @throws SocketTimeoutException if timeout expires before connecting
     * @throws  java.nio.channels.IllegalBlockingModeException
     *          if this socket has an associated channel,
     *          and the channel is in non-blocking mode
     * @throws  IllegalArgumentException if endpoint is null or is a
     *          SocketAddress subclass not supported by this socket
     * @since 1.4
     * @spec JSR-51
     */
public void connect(SocketAddress endpoint, int timeout) throws IOException {
    if (endpoint == null) throw new IllegalArgumentException('connect: The address can't be null');
    if (timeout < 0) throw new IllegalArgumentException('connect: timeout can't be negative');
    if (isClosed()) throw new SocketException('Socket is closed');
    if (!oldImpl && isConnected()) throw new SocketException('already connected');
    if (!(endpoint instanceof InetSocketAddress)) throw new IllegalArgumentException('Unsupported address type');
    InetSocketAddress epoint = (InetSocketAddress) endpoint;
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        if (epoint.isUnresolved()) security.checkConnect(epoint.getHostName(), epoint.getPort()); else security.checkConnect(epoint.getAddress().getHostAddress(), epoint.getPort());
    }
    if (!created) createImpl(true);
    if (!oldImpl) impl.connect(epoint, timeout); else if (timeout == 0) {
        if (epoint.isUnresolved()) impl.connect(epoint.getAddress().getHostName(), epoint.getPort()); else impl.connect(epoint.getAddress(), epoint.getPort());
    } else throw new UnsupportedOperationException('SocketImpl.connect(addr, timeout)');
    connected = true;
    bound = true;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getKeepAlive()

/**
     * Tests if SO_KEEPALIVE is enabled.
     * @return a <code>boolean</code> indicating whether or not SO_KEEPALIVE is enabled.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @since   1.3
     * @see #setKeepAlive(boolean)
     */
public boolean getKeepAlive() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    return ((Boolean) getImpl().getOption(SocketOptions.SO_KEEPALIVE)).booleanValue();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getOOBInline()

/**
     * Tests if OOBINLINE is enabled.
     * @return a <code>boolean</code> indicating whether or not OOBINLINE is enabled.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @since   1.4
     * @see #setOOBInline(boolean)
     */
public boolean getOOBInline() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    return ((Boolean) getImpl().getOption(SocketOptions.SO_OOBINLINE)).booleanValue();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getOutputStream()

/**
     * Returns an output stream for this socket.
     *  If this socket has an associated channel then the resulting output
     * stream delegates all of its operations to the channel.  If the channel
     * is in non-blocking mode then the output stream's <tt>write</tt>
     * operations will throw an {@link
     * java.nio.channels.IllegalBlockingModeException}.
     * @return     an output stream for writing bytes to this socket.
     * @exception  IOException  if an I/O error occurs when creating the
     *               output stream or if the socket is not connected.
     * @revised 1.4
     * @spec JSR-51
     */
public OutputStream getOutputStream() throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (!isConnected()) throw new SocketException('Socket is not connected');
    if (isOutputShutdown()) throw new SocketException('Socket output is shutdown');
    final Socket s = this;
    OutputStream os = null;
    try {
        os = (OutputStream) AccessController.doPrivileged(new PrivilegedExceptionAction() {

            public Object run() throws IOException {
                return impl.getOutputStream();
            }
        });
    } catch (java.security.PrivilegedActionException e) {
        throw (IOException) e.getException();
    }
    return os;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getReceiveBufferSize()

/**
     * Gets the value of the SO_RCVBUF option for this <tt>Socket</tt>, 
     * that is the buffer size used by the platform for 
     * input on this <tt>Socket</tt>.
     * @return the value of the SO_RCVBUF option for this <tt>Socket</tt>.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @see #setReceiveBufferSize(int)
     * @since 1.2
     */
public synchronized int getReceiveBufferSize() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    int result = 0;
    Object o = getImpl().getOption(SocketOptions.SO_RCVBUF);
    if (o instanceof Integer) {
        result = ((Integer) o).intValue();
    }
    return result;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getReuseAddress()

/**
     * Tests if SO_REUSEADDR is enabled.
     * @return a <code>boolean</code> indicating whether or not SO_REUSEADDR is enabled.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @since   1.4
     * @see #setReuseAddress(boolean)
     */
public boolean getReuseAddress() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    return ((Boolean) (getImpl().getOption(SocketOptions.SO_REUSEADDR))).booleanValue();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getSendBufferSize()

/**
     * Get value of the SO_SNDBUF option for this <tt>Socket</tt>, 
     * that is the buffer size used by the platform 
     * for output on this <tt>Socket</tt>.
     * @return the value of the SO_SNDBUF option for this <tt>Socket</tt>.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @see #setSendBufferSize(int)
     * @since 1.2
     */
public synchronized int getSendBufferSize() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    int result = 0;
    Object o = getImpl().getOption(SocketOptions.SO_SNDBUF);
    if (o instanceof Integer) {
        result = ((Integer) o).intValue();
    }
    return result;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getSoLinger()

/**
     * Returns setting for SO_LINGER. -1 returns implies that the
     * option is disabled.
     * The setting only affects socket close.
     * @return the setting for SO_LINGER.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @since   JDK1.1
     * @see #setSoLinger(boolean, int)
     */
public int getSoLinger() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    Object o = getImpl().getOption(SocketOptions.SO_LINGER);
    if (o instanceof Integer) {
        return ((Integer) o).intValue();
    } else {
        return -1;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getSoTimeout()

/**
     * Returns setting for SO_TIMEOUT.  0 returns implies that the
     * option is disabled (i.e., timeout of infinity).
     * @return the setting for SO_TIMEOUT
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @since   JDK1.1
     * @see #setSoTimeout(int)
     */
public synchronized int getSoTimeout() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    Object o = getImpl().getOption(SocketOptions.SO_TIMEOUT);
    if (o instanceof Integer) {
        return ((Integer) o).intValue();
    } else {
        return 0;
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.getTcpNoDelay()

/**
     * Tests if TCP_NODELAY is enabled.
     * @return a <code>boolean</code> indicating whether or not TCP_NODELAY is enabled.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @since   JDK1.1
     * @see #setTcpNoDelay(boolean)
     */
public boolean getTcpNoDelay() throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    return ((Boolean) getImpl().getOption(SocketOptions.TCP_NODELAY)).booleanValue();
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setKeepAlive(boolean)

/**
     * Enable/disable SO_KEEPALIVE.
     * @param on     whether or not to have socket keep alive turned on.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @since 1.3 
     * @see #getKeepAlive()
     */
public void setKeepAlive(boolean on) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_KEEPALIVE, Boolean.valueOf(on));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setOOBInline(boolean)

/**
     * Enable/disable OOBINLINE (receipt of TCP urgent data)
     * By default, this option is disabled and TCP urgent data received on a 
     * socket is silently discarded. If the user wishes to receive urgent data, then
     * this option must be enabled. When enabled, urgent data is received
     * inline with normal data. 
     * Note, only limited support is provided for handling incoming urgent 
     * data. In particular, no notification of incoming urgent data is provided 
     * and there is no capability to distinguish between normal data and urgent
     * data unless provided by a higher level protocol.
     * @param on <code>true</code> to enable OOBINLINE, 
     * <code>false</code> to disable.
     * @exception SocketException if there is an error 
     * in the underlying protocol, such as a TCP error.
     * @since   1.4
     * @see #getOOBInline()
     */
public void setOOBInline(boolean on) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_OOBINLINE, Boolean.valueOf(on));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setReceiveBufferSize(int)

/**
     * Sets the SO_RCVBUF option to the specified value for this
     * <tt>Socket</tt>. The SO_RCVBUF option is used by the platform's
     * networking code as a hint for the size to set
     * the underlying network I/O buffers.
     * Increasing the receive buffer size can increase the performance of
     * network I/O for high-volume connection, while decreasing it can
     * help reduce the backlog of incoming data. 
     * Because SO_RCVBUF is a hint, applications that want to
     * verify what size the buffers were set to should call
     * {@link #getReceiveBufferSize()}.
     * The value of SO_RCVBUF is also used to set the TCP receive window
     * that is advertized to the remote peer. Generally, the window size
     * can be modified at any time when a socket is connected. However, if
     * a receive window larger than 64K is required then this must be requested
     * <B>before</B> the socket is connected to the remote peer. There are two
     * cases to be aware of:
     * <ol>
     * <li>For sockets accepted from a ServerSocket, this must be done by calling
     * {@link ServerSocket#setReceiveBufferSize(int)} before the ServerSocket 
     * is bound to a local address.</li>
     * <li>For client sockets, setReceiveBufferSize() must be called before
     * connecting the socket to its remote peer.</li></ol>
     * @param size the size to which to set the receive buffer
     * size. This value must be greater than 0.
     * @exception IllegalArgumentException if the value is 0 or is
     * negative.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error.
     * @see #getReceiveBufferSize()
     * @see ServerSocket#setReceiveBufferSize(int)
     * @since 1.2
     */
public synchronized void setReceiveBufferSize(int size) throws SocketException {
    if (size <= 0) {
        throw new IllegalArgumentException('invalid receive size');
    }
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_RCVBUF, new Integer(size));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setReuseAddress(boolean)

/**
     * Enable/disable the SO_REUSEADDR socket option.
     * When a TCP connection is closed the connection may remain
     * in a timeout state for a period of time after the connection
     * is closed (typically known as the <tt>TIME_WAIT</tt> state
     * or <tt>2MSL</tt> wait state).
     * For applications using a well known socket address or port 
     * it may not be possible to bind a socket to the required
     * <tt>SocketAddress</tt> if there is a connection in the
     * timeout state involving the socket address or port.
     * Enabling <tt>SO_REUSEADDR</tt> prior to binding the socket
     * using {@link #bind(SocketAddress)} allows the socket to be
     * bound even though a previous connection is in a timeout
     * state.
     * When a <tt>Socket</tt> is created the initial setting
     * of <tt>SO_REUSEADDR</tt> is disabled.
     * The behaviour when <tt>SO_REUSEADDR</tt> is enabled or
     * disabled after a socket is bound (See {@link #isBound()})
     * is not defined.
     * @param on  whether to enable or disable the socket option
     * @exception SocketException if an error occurs enabling or
     *            disabling the <tt>SO_RESUEADDR</tt> socket option,
     *    or the socket is closed.
     * @since 1.4
     * @see #getReuseAddress()     
     * @see #bind(SocketAddress)
     * @see #isClosed()
     * @see #isBound()
     */
public void setReuseAddress(boolean on) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_REUSEADDR, Boolean.valueOf(on));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setSendBufferSize(int)

/**
     * Sets the SO_SNDBUF option to the specified value for this
     * <tt>Socket</tt>. The SO_SNDBUF option is used by the platform's
     * networking code as a hint for the size to set
     * the underlying network I/O buffers.
     * Because SO_SNDBUF is a hint, applications that want to
     * verify what size the buffers were set to should call
     * {@link #getSendBufferSize()}.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @param size the size to which to set the send buffer
     * size. This value must be greater than 0.
     * @exception IllegalArgumentException if the 
     * value is 0 or is negative.
     * @see #getSendBufferSize()
     * @since 1.2
     */
public synchronized void setSendBufferSize(int size) throws SocketException {
    if (!(size > 0)) {
        throw new IllegalArgumentException('negative send size');
    }
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.SO_SNDBUF, new Integer(size));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setSoLinger(boolean, int)

/**
     * Enable/disable SO_LINGER with the specified linger time in seconds. 
     * The maximum timeout value is platform specific.
     * The setting only affects socket close.
     * @param on     whether or not to linger on.
     * @param linger how long to linger for, if on is true.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @exception IllegalArgumentException if the linger value is negative.
     * @since JDK1.1
     * @see #getSoLinger()
     */
public void setSoLinger(boolean on, int linger) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (!on) {
        getImpl().setOption(SocketOptions.SO_LINGER, new Boolean(on));
    } else {
        if (linger < 0) {
            throw new IllegalArgumentException('invalid value for SO_LINGER');
        }
        if (linger > 65535) linger = 65535;
        getImpl().setOption(SocketOptions.SO_LINGER, new Integer(linger));
    }
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setSoTimeout(int)

/**
     *  Enable/disable SO_TIMEOUT with the specified timeout, in
     *  milliseconds.  With this option set to a non-zero timeout,
     *  a read() call on the InputStream associated with this Socket
     *  will block for only this amount of time.  If the timeout expires,
     *  a <B>java.net.SocketTimeoutException</B> is raised, though the
     *  Socket 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.
     * @param timeout the specified timeout, in milliseconds.
     * @exception SocketException if there is an error
     * in the underlying protocol, such as a TCP error. 
     * @since   JDK 1.1
     * @see #getSoTimeout()
     */
public synchronized void setSoTimeout(int timeout) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (timeout < 0) throw new IllegalArgumentException('timeout can't be negative');
    getImpl().setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setTcpNoDelay(boolean)

/**
     * Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).
     * @param on <code>true</code> to enable TCP_NODELAY, 
     * <code>false</code> to disable.
     * @exception SocketException if there is an error 
     * in the underlying protocol, such as a TCP error.
     * @since   JDK1.1
     * @see #getTcpNoDelay()
     */
public void setTcpNoDelay(boolean on) throws SocketException {
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.TCP_NODELAY, Boolean.valueOf(on));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setTrafficClass(int)

/**
     * Sets traffic class or type-of-service octet in the IP
     * header for packets sent from this Socket.
     * As the underlying network implementation may ignore this
     * value applications should consider it a hint.
     * <P> The tc <B>must</B> be in the range <code> 0 <= tc <=
     * 255</code> or an IllegalArgumentException will be thrown.
     * Notes:
     *  for Internet Protocol v4 the value consists of an octet
     * with precedence and TOS fields as detailed in RFC 1349. The
     * TOS field is bitset created by bitwise-or'ing values such
     * the following :-
     * <UL>
     * <LI><CODE>IPTOS_LOWCOST (0x02)</CODE></LI>
     * <LI><CODE>IPTOS_RELIABILITY (0x04)</CODE></LI>
     * <LI><CODE>IPTOS_THROUGHPUT (0x08)</CODE></LI>
     * <LI><CODE>IPTOS_LOWDELAY (0x10)</CODE></LI>
     * </UL>
     * The last low order bit is always ignored as this
     * corresponds to the MBZ (must be zero) bit.
     * Setting bits in the precedence field may result in a
     * SocketException indicating that the operation is not
     * permitted.
     * for Internet Protocol v6 <code>tc</code> is the value that
     * would be placed into the sin6_flowinfo field of the IP header.
     * @param tc        an <code>int</code> value for the bitset.
     * @throws SocketException if there is an error setting the
     * traffic class or type-of-service
     * @since 1.4
     * @see #getTrafficClass
     */
public void setTrafficClass(int tc) throws SocketException {
    if (tc < 0 || tc > 255) throw new IllegalArgumentException('tc is not in range 0 -- 255');
    if (isClosed()) throw new SocketException('Socket is closed');
    getImpl().setOption(SocketOptions.IP_TOS, new Integer(tc));
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.shutdownOutput()

/**
     * Disables the output stream for this socket.
     * For a TCP socket, any previously written data will be sent
     * followed by TCP's normal connection termination sequence.
     * If you write to a socket output stream after invoking 
     * shutdownOutput() on the socket, the stream will throw 
     * an IOException.
     * @exception IOException if an I/O error occurs when shutting down this
     * socket.
     * @since 1.3
     * @see java.net.Socket#shutdownInput()
     * @see java.net.Socket#close()
     * @see java.net.Socket#setSoLinger(boolean, int)
     * @see #isOutputShutdown
     */
public void shutdownOutput() throws IOException {
    if (isClosed()) throw new SocketException('Socket is closed');
    if (!isConnected()) throw new SocketException('Socket is not connected');
    if (isOutputShutdown()) throw new SocketException('Socket output is already shutdown');
    getImpl().shutdownOutput();
    shutOut = true;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.connect(SocketAddress)

/**
     * Connects this socket to a remote socket address (IP address + port number).
     * @param addr The remote address.
     * @throws SocketException if the connect fails
     * @throws IllegalArgumentException if addr is null or addr is a SocketAddress
     *  subclass not supported by this socket
     * @since 1.4
     * @see #connect
     */
public void connect(SocketAddress addr) throws SocketException {
    if (addr == null) throw new IllegalArgumentException('Address can't be null');
    if (!(addr instanceof InetSocketAddress)) throw new IllegalArgumentException('Unsupported address type');
    InetSocketAddress epoint = (InetSocketAddress) addr;
    if (epoint.isUnresolved()) throw new SocketException('Unresolved address');
    connectInternal(epoint.getAddress(), epoint.getPort());
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.sendUrgentData(int)

/**
     * Send one byte of urgent data on the socket. The byte to be sent is the lowest eight
     * bits of the data parameter. The urgent byte is
     * sent after any preceding writes to the socket OutputStream
     * and before any future writes to the OutputStream.
     * @param data The byte of data to send
     * @exception IOException if there is an error
     *  sending the data.
     * @since 1.4
     */
public void sendUrgentData(int data) throws IOException {
    if (!getImpl().supportsUrgentData()) {
        throw new SocketException('Urgent data not supported');
    }
    getImpl().sendUrgentData(data);
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.createImpl()

void createImpl() throws SocketException {
    if (impl == null) {
        if (factory != null) {
            impl = factory.createDatagramSocketImpl();
            checkOldImpl();
        } else {
            if (implClass == null) {
                String prefix = null;
                try {
                    prefix = (String) AccessController.doPrivileged(new sun.security.action.GetPropertyAction('impl.prefix', 'Plain'));
                    implClass = Class.forName('java.net.' + prefix + 'DatagramSocketImpl');
                } catch (Exception e) {
                    System.err.println('Can't find class: java.net.' + prefix + 'DatagramSocketImpl: check impl.prefix property');
                }
                if (implClass == null) implClass = java.net.PlainDatagramSocketImpl.class;
            }
            try {
                impl = (DatagramSocketImpl) implClass.newInstance();
            } catch (Exception e) {
                throw new SocketException('can't instantiate DatagramSocketImpl');
            }
            if (!(impl instanceof java.net.PlainDatagramSocketImpl)) checkOldImpl();
        }
    }
    impl.create();
    created = true;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.DatagramSocket.setDatagramSocketImplFactory(DatagramSocketImplFactory)

/**
     * Sets the datagram socket implementation factory for the
     * application. The factory can be specified only once.
     * When an application creates a new datagram socket, the socket
     * implementation factory's <code>createDatagramSocketImpl</code> method is
     * called to create the actual datagram socket implementation.
     * Passing <code>null</code> to the method is a no-op unless the factory
     * was already set.
     * If there is a security manager, this method first calls
     * the security manager's <code>checkSetFactory</code> method 
     * to ensure the operation is allowed. 
     * This could result in a SecurityException.
     * @param      fac   the desired factory.
     * @exception  IOException  if an I/O error occurs when setting the
     *              datagram socket factory.
     * @exception  SocketException  if the factory is already defined.
     * @exception  SecurityException  if a security manager exists and its  
     *             <code>checkSetFactory</code> method doesn't allow the 
     operation.
     * @see        
     java.net.DatagramSocketImplFactory#createDatagramSocketImpl()
     * @see       SecurityManager#checkSetFactory
     */
public static synchronized void setDatagramSocketImplFactory(DatagramSocketImplFactory fac) throws IOException {
    if (factory != null) {
        throw new SocketException('factory already defined');
    }
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkSetFactory();
    }
    factory = fac;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.ServerSocket.setSocketFactory(SocketImplFactory)

/**
     * Sets the server socket implementation factory for the 
     * application. The factory can be specified only once. 
     * When an application creates a new server socket, the socket 
     * implementation factory's <code>createSocketImpl</code> method is 
     * called to create the actual socket implementation. 
     * Passing <code>null</code> to the method is a no-op unless the factory
     * was already set.
     * If there is a security manager, this method first calls
     * the security manager's <code>checkSetFactory</code> method 
     * to ensure the operation is allowed. 
     * This could result in a SecurityException.
     * @param      fac   the desired factory.
     * @exception  IOException  if an I/O error occurs when setting the
     *               socket factory.
     * @exception  SocketException  if the factory has already been defined.
     * @exception  SecurityException  if a security manager exists and its  
     *             <code>checkSetFactory</code> method doesn't allow the operation.
     * @see        java.net.SocketImplFactory#createSocketImpl()
     * @see        SecurityManager#checkSetFactory
     */
public static synchronized void setSocketFactory(SocketImplFactory fac) throws IOException {
    if (factory != null) {
        throw new SocketException('factory already defined');
    }
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkSetFactory();
    }
    factory = fac;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.net.Socket.setSocketImplFactory(SocketImplFactory)

/**
     * Sets the client socket implementation factory for the
     * application. The factory can be specified only once.
     * When an application creates a new client socket, the socket
     * implementation factory's <code>createSocketImpl</code> method is
     * called to create the actual socket implementation.
     * Passing <code>null</code> to the method is a no-op unless the factory
     * was already set.
     * If there is a security manager, this method first calls
     * the security manager's <code>checkSetFactory</code> method 
     * to ensure the operation is allowed. 
     * This could result in a SecurityException.
     * @param      fac   the desired factory.
     * @exception  IOException  if an I/O error occurs when setting the
     *               socket factory.
     * @exception  SocketException  if the factory is already defined.
     * @exception  SecurityException  if a security manager exists and its  
     *             <code>checkSetFactory</code> method doesn't allow the operation.
     * @see        java.net.SocketImplFactory#createSocketImpl()
     * @see        SecurityManager#checkSetFactory
     */
public static synchronized void setSocketImplFactory(SocketImplFactory fac) throws IOException {
    if (factory != null) {
        throw new SocketException('factory already defined');
    }
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkSetFactory();
    }
    factory = fac;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

java.rmi.server.RMISocketFactory.setSocketFactory(RMISocketFactory)

/**
     * Set the global socket factory from which RMI gets sockets (if the
     * remote object is not associated with a specific client and/or server
     * socket factory). The RMI socket factory can only be set once. Note: The
     * RMISocketFactory may only be set if the current security manager allows
     * setting a socket factory; if disallowed, a SecurityException will be
     * thrown.
     * @param fac the socket factory
     * @exception IOException if the RMI socket factory is already set
     * @exception  SecurityException  if a security manager exists and its  
     *             <code>checkSetFactory</code> method doesn't allow the operation.
     * @see #getSocketFactory
     * @see java.lang.SecurityManager#checkSetFactory()
     * @since JDK1.1
     */
public static synchronized void setSocketFactory(RMISocketFactory fac) throws IOException {
    if (factory != null) {
        throw new SocketException('factory already defined');
    }
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkSetFactory();
    }
    factory = fac;
}

Source: "Java SE Downloads: Java SE 6 JDK Source Code", at: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Comments

Popular posts from this blog

NullPointerException

java.lang.NullPointerException NullPointerException is described in the javadoc comments as: Thrown when an application attempts to use null in a case where an object is required. These include: Calling the instance method of a null object. Accessing or modifying the field of a null object. Taking the length of null as if it were an array. Accessing or modifying the slots of null as if it were an array. Throwing null as if it were a Throwable value. Applications should throw instances of this class to indicate other illegal uses of the null object. author: unascribed version: 1.19, 12/19/03 since: JDK1.0 Where is this exception thrown? Following, is a list of exception messages cross-referenced to the source code responsible for throwing them. Click on the method link to view the code and see how the exception is thrown. The message ' java.lang.NullPointerException: ' is thrown within the method: com.sun.corba.se.impl.interceptors.ClientRequestInfoImpl.get_r...

Connection refused: No available router to destination

This is a simple symptom-cause-solution blog entry only. I hope these blogs will help fellow administrators. Symptom The following exception occurs in WebLogic server logs. Most likely to occur during WebLogic server start-up, but similar exceptions may occur at other times. java.net.ConnectException: t3://myserver:8000: Destination unreachable; nested exception is: java.net.ConnectException: Connection refused: connect; No available router to destination] at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:49) at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:773) at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:363) at weblogic.jndi.Environment.getContext(Environment.java:307) at weblogic.jndi.Environment.getContext(Environment.java:277) Cause This message (Connection refused: connect; No available ...

Recovering WebLogic Passwords

In one of my previous articles ( here ) I explained that the SerializedSystemIni.dat file in WebLogic contains the key used to encrypt and decrypt passwords. If you're not currently keeping this file secure I suggest you do, as with it someone can (to name a few things): Decrypt the WebLogic admin username and password from boot.properties. Recover database passwords, if JDBC Connection pools are configured, from config.xml. Recover the keystore passwords from config.xml and obtain SSL certificates stored in the jks keystores. Essentially, they can do whatever they want, so if you don't know who can read your SerializedSystemIni.dat files, look... now. In this article I will show how easy it is for this file to be used to recover lost passwords via a simple WLST script. The Script The script I use to decrypt passwords is incredibly short, and it works with WebLogic 8, 9 and 10 (probably for version 7 too). To use it, just create a new file called decryptpwd.py and paste the fol...