Socket (Java SE 25 & JDK 25)
- 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.
protectedCreates an unconnected Socket with a user-specified SocketImpl.
-
Method Summary
voidBinds the socket to a local address.
voidclose()voidConnects this socket to the server.
voidConnects this socket to the server with a specified timeout value.
Returns the unique
SocketChannelobject associated with this socket, if any.Returns the address to which the socket is connected.
Returns an input stream for this socket.
booleanGets the local address to which the socket is bound.
intReturns the local port number to which this socket is bound.
Returns the address of the endpoint this socket is bound to.
boolean<T> TReturns the value of a socket option.
Returns an output stream for this socket.
intgetPort()Returns the remote port number to which this socket is connected.
intGets the value of the
SO_RCVBUFoption for thisSocket, that is the buffer size used by the platform for input on thisSocket.Returns the address of the endpoint this socket is connected to, or
nullif it is unconnected.booleanintGet value of the
SO_SNDBUFoption for thisSocket, that is the buffer size used by the platform for output on thisSocket.intReturns setting for
SO_LINGER. -1 returns implies that the option is disabled.intReturns setting for
SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).booleanintGets traffic class or type-of-service in the IP header for packets sent from this Socket
booleanisBound()Returns the binding state of the socket.
booleanisClosed()Returns the closed state of the socket.
booleanReturns the connection state of the socket.
booleanReturns whether the read-half of the socket connection is closed.
booleanReturns whether the write-half of the socket connection is closed.
voidsendUrgentData(int data) Send one byte of urgent data on the socket.
voidsetKeepAlive(boolean on) voidsetOOBInline(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.
voidsetPerformancePreferences(int connectionTime, int latency, int bandwidth) Sets performance preferences for this socket.
voidsetReceiveBufferSize(int size) Sets the
SO_RCVBUFoption to the specified value for thisSocket.voidsetReuseAddress(boolean on) voidsetSendBufferSize(int size) Sets the
SO_SNDBUFoption to the specified value for thisSocket.static voidvoidsetSoLinger(boolean on, int linger) Enable/disable
SO_LINGERwith the specified linger time in seconds.voidsetSoTimeout(int timeout) Enable/disable
SO_TIMEOUTwith the specified timeout, in milliseconds.voidsetTcpNoDelay(boolean on) Enable/disable
TCP_NODELAY(disable/enable Nagle's algorithm).voidsetTrafficClass(int tc) Sets traffic class or type-of-service octet in the IP header for packets sent from this Socket.
voidPlaces the input stream for this socket at "end of stream".
voidDisables 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
-