ServerSocket (Java SE 25 & JDK 25)
- 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) Sets performance preferences for this ServerSocket.
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.
-
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
-