ServerSocket (Java SE 26 & JDK 26)
- All Implemented Interfaces:
Closeable, AutoCloseable
- Direct Known Subclasses:
SSLServerSocket
-
Constructor Summary
Constructors
Creates an unbound server socket.
ServerSocket(int port) Creates a server socket, bound to the specified port.
ServerSocket(int port, int backlog) Creates a server socket and binds it to the specified local port number, with the specified backlog.
Create a server with the specified port, listen backlog, and local IP address to bind to.
protectedCreates a server socket with a user-specified
SocketImpl. -
Method Summary
accept()Listens for a connection to be made to this socket and accepts it.
voidBinds the
ServerSocketto a specific address (IP address and port number).voidBinds the
ServerSocketto a specific address (IP address and port number).voidclose()Returns the local address of this server socket.
intReturns the port number on which this socket is listening.
Returns the address of the endpoint this socket is bound to.
<T> TReturns the value of a socket option.
intGets the value of the
SO_RCVBUFoption for thisServerSocket, that is the proposed buffer size that will be used for Sockets accepted from thisServerSocket.booleanintRetrieve setting for
SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).protected final voidSubclasses of ServerSocket use this method to override accept() to return their own subclass of socket.
booleanisBound()Returns the binding state of the ServerSocket.
booleanisClosed()Returns the closed state of the ServerSocket.
Sets the value of a socket option.
voidsetPerformancePreferences(int connectionTime, int latency, int bandwidth) Deprecated, for removal: This API element is subject to removal in a future version.
voidsetReceiveBufferSize(int size) Sets a default proposed value for the
SO_RCVBUFoption for sockets accepted from thisServerSocket.voidsetReuseAddress(boolean on) static voidvoidsetSoTimeout(int timeout) Enable/disable
SO_TIMEOUTwith the specified timeout, in milliseconds.Returns a set of the socket options supported by this server socket.
toString()Returns the implementation address and implementation port of this socket as a
String.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitCreates and returns a copy of this object.
booleanIndicates whether some other object is "equal to" this one.
protected voidDeprecated, for removal: This API element is subject to removal in a future version.
Returns the runtime class of this
Object.intReturns a hash code value for this object.
final voidWakes up a single thread that is waiting on this object's monitor.
final voidWakes up all threads that are waiting on this object's monitor.
final voidCauses the current thread to wait until it is awakened, typically by being notified or interrupted.
final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Constructor Details
-
ServerSocket
-
ServerSocket
-
ServerSocket
-
ServerSocket
-
ServerSocket
-
-
Method Details
-
bind
-
bind
-
getInetAddress
-
getLocalPort
-
getLocalSocketAddress
-
accept
-
implAccept
-
close
-
getChannel
-
isBound
-
isClosed
-
setSoTimeout
-
getSoTimeout
-
setReuseAddress
-
getReuseAddress
-
toString
-
setSocketFactory
-
setReceiveBufferSize
-
getReceiveBufferSize
-
setPerformancePreferences
-
setOption
-
getOption
-
supportedOptions
-