Java Socket shutdownInput() method25 Mar 2025 | 2 min read The shutdownInput() method of Java Socket class places the input stream for the specified socket at the end of the stream. When this method is invoked on the socket, the stream's available method returns 0, and its read methods return -1 (end of stream). SyntaxParameterNA ReturnNA ThrowsIOException - if an I/O error occurs while shutting down the given socket Example 1Output: Output The socket is connected: true The socket is bounded: true Input is shutdown: true Example 2Output: The socket is connected: true The socket is bounded: true Input is shutdown: true Example 3Output: Exception in thread "main" java.net.SocketException: Socket is not connected at java.net.Socket.shutdownInput(Socket.java:1523) at com.tpointtech.JavaSocketShutdownInputExample3.main(JavaSocketShutdownInputExample3.java:11) Next TopicJava Socket Class |
Java method The getTcpNoDelay () method of Java Socket class returns the setting for SO_TIMEOUT option if it is enabled, else it returns false. Syntax public boolean getTcpNoDelay () Parameter NA Return The getTcpNoDelay () method returns a Boolean value 'true' if the TCP_NODELAY is enabled. Throws SocketException - if an error is...
2 min read
Java Socket setReuseAddress () method The setReuseAddress () method of Java Socket class enables or disables the SO_REUSEADDR socket option. The initial setting of SO_REUSEADDR is disabled. Syntax public void setReuseAddress (boolean on) throws SocketException Parameter The parameter 'on' states whether the SO_REUSEADDR option should be enabled or disabled. Return NA Throws SocketException -...
3 min read
Java method The getInputStream() method of Java Socket class returns an input stream for the given socket. If you close the returned InputStream, then it will close the linked socket. Syntax public InputStream getInputStream () throws IOException Parameter NA Return The getInputStream() returns an input stream for reading bytes...
3 min read
Java Socket isClosed () method The isClosed () method of Java Socket class returns the closed state of the socket. Syntax public boolean isClosed () Parameter NA Return The isClosed () method would return a Boolean value 'true' if the socket has been closed successfully. Example 1 import java.io.IOException; import java.net.*; public class JavaSocketIsClosedExample1 { ...
1 min read
Java method The isBound () method of Java Socket class returns a Boolean value representing the binding state of the socket. This method would continue to return 'true' for a closed socket, if it was bound before being closed. Syntax public boolean isBound() Parameter NA Return The isBound () method would...
3 min read
Java method The setSoTimeout () method of Java Socket class enables or disables the SO_TIMEOUT option with the given timeout value, in milliseconds. The timeout value should be greater than 0 otherwise, it will throw an error. Syntax public void setSoTimeout (int timeout) throws SocketException Parameter The...
3 min read
Java method The isConnected () method of Java Socket class returns the connection state of the socket. This method would continue to return the connection state which was there before being closed. Syntax public boolean isConnected() Parameter NA Return The isConnected () method would return a Boolean value 'true' if the...
3 min read
Java method The getChannel() method of Java Socket class returns the unique SocketChannel object linked with this socket. Syntax public SocketChannel getChannel() Parameter NA Return The getChannel() method either returns the socket channel linked with this socket or returns null if the socket was not created for the specified channel. Example...
2 min read
Java method The getInetAddress() method of Java Socket class returns the address to which the socket is connected. If the socket is being closed, this method will return the connected address after the socket is closed. Syntax public InetAddress getInetAddress () Parameter NA Return The getInetAddress () method either returns the...
3 min read
Java method The setKeepAlive() method of Java Socket class returns a Boolean value 'true' if the write-half of the socket connection has been closed successfully else it returns false. Syntax public void setKeepAlive (boolean on) throws SocketException Parameter The parameter 'on' represents whether the socket should be enabled or...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India