All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
SSLSocket

  • Constructor Summary

    Constructors

    Socket()

    Creates an unconnected Socket.

    Creates a stream socket and connects it to the specified port number on the named host.

    Socket(String host, int port, boolean stream)

    Deprecated, for removal: This API element is subject to removal in a future version.

    Creates a socket and connects it to the specified remote host on the specified remote port.

    Creates a stream socket and connects it to the specified port number at the specified IP address.

    Deprecated, for removal: This API element is subject to removal in a future version.

    Creates a socket and connects it to the specified remote address on the specified remote port.

    Creates an unconnected socket, specifying the type of proxy, if any, that should be used regardless of any other settings.

    protected

    Creates an unconnected Socket with a user-specified SocketImpl.

  • Method Summary

    void

    Binds the socket to a local address.

    void

    close()

    void

    Connects this socket to the server.

    void

    Connects this socket to the server with a specified timeout value.

    Returns the unique SocketChannel object associated with this socket, if any.

    Returns the address to which the socket is connected.

    Returns an input stream for this socket.

    boolean

    Gets the local address to which the socket is bound.

    int

    Returns the local port number to which this socket is bound.

    Returns the address of the endpoint this socket is bound to.

    boolean

    <T> T

    Returns the value of a socket option.

    Returns an output stream for this socket.

    int

    getPort()

    Returns the remote port number to which this socket is connected.

    int

    Gets the value of the SO_RCVBUF option for this Socket, that is the buffer size used by the platform for input on this Socket.

    Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

    boolean

    int

    Get value of the SO_SNDBUF option for this Socket, that is the buffer size used by the platform for output on this Socket.

    int

    Returns setting for SO_LINGER. -1 returns implies that the option is disabled.

    int

    Returns setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).

    boolean

    int

    Gets traffic class or type-of-service in the IP header for packets sent from this Socket

    boolean

    isBound()

    Returns the binding state of the socket.

    boolean

    isClosed()

    Returns the closed state of the socket.

    boolean

    Returns the connection state of the socket.

    boolean

    Returns whether the read-half of the socket connection is closed.

    boolean

    Returns whether the write-half of the socket connection is closed.

    void

    sendUrgentData(int data)

    Send one byte of urgent data on the socket.

    void

    setKeepAlive(boolean on)

    void

    setOOBInline(boolean on)

    Enable/disable SO_OOBINLINE (receipt of TCP urgent data) By default, this option is disabled and TCP urgent data received on a socket is silently discarded.

    Sets the value of a socket option.

    void

    setPerformancePreferences(int connectionTime, int latency, int bandwidth)

    Sets performance preferences for this socket.

    void

    setReceiveBufferSize(int size)

    Sets the SO_RCVBUF option to the specified value for this Socket.

    void

    setReuseAddress(boolean on)

    void

    setSendBufferSize(int size)

    Sets the SO_SNDBUF option to the specified value for this Socket.

    static void

    void

    setSoLinger(boolean on, int linger)

    Enable/disable SO_LINGER with the specified linger time in seconds.

    void

    setSoTimeout(int timeout)

    Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

    void

    setTcpNoDelay(boolean on)

    Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).

    void

    setTrafficClass(int tc)

    Sets traffic class or type-of-service octet in the IP header for packets sent from this Socket.

    void

    Places the input stream for this socket at "end of stream".

    void

    Disables the output stream for this socket.

    Returns a set of the socket options supported by this socket.

    toString()

    Converts this socket to a String.

  • Constructor Details

    • Socket

    • Socket

    • Socket

    • Socket

    • Socket

    • Socket

    • Socket

    • Socket

    • Socket

  • Method Details

    • connect

    • connect

    • bind

    • getInetAddress

    • getLocalAddress

    • getPort

    • getLocalPort

    • getRemoteSocketAddress

    • getLocalSocketAddress

    • getChannel

    • getInputStream

    • getOutputStream

    • setTcpNoDelay

    • getTcpNoDelay

    • setSoLinger

    • getSoLinger

    • sendUrgentData

    • setOOBInline

    • getOOBInline

    • setSoTimeout

    • getSoTimeout

    • setSendBufferSize

    • getSendBufferSize

    • setReceiveBufferSize

    • getReceiveBufferSize

    • setKeepAlive

    • getKeepAlive

    • setTrafficClass

    • getTrafficClass

    • setReuseAddress

    • getReuseAddress

    • close

    • shutdownInput

    • shutdownOutput

    • toString

    • isConnected

    • isBound

    • isClosed

    • isInputShutdown

    • isOutputShutdown

    • setSocketImplFactory

    • setPerformancePreferences

    • setOption

    • getOption

    • supportedOptions