Java Socket setSendBufferSize () method25 Mar 2025 | 2 min read The setSendBufferSize () method of Java Socket class sets the SO_SNDBUF option to the given value for this socket. The size value should be greater than 0. SyntaxParameterThe parameter 'size' represents the size to which the send buffer size is set. ReturnNA ThrowsIllegalArgumentException - if the size is 0 or less than zero. SocketException - if an error is there in the underlying protocol, such as a TCP error. Example 1Output: Send Buffer size: 67 Example 2Output: Exception in thread "main" java.lang.IllegalArgumentException: negative send size at java.net.Socket.setSendBufferSize(Socket.java:1193) at com.tpointtech.JavaSocketSetSendBufferSizeExample2.main( JavaSocketSetSendBufferSizeExample2.java:11) Example 3Output: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.setSendBufferSize(Socket.java:1196) at com.tpointtech.JavaSocketSetSendBufferSizeExample2.main( JavaSocketSetSendBufferSizeExample2.java:13) Next TopicJava Socket Class |
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 getSoLinger () method of Java Socket class returns the setting if the SO_Linger option is set else it returns -1 if the option is disabled. This method only affects the setting for SO_LINGER. Syntax public int getSoLinger () Parameter NA Return The getSoLinger () method returns the setting for...
3 min read
Java method The close() method of Java Socket class closes the specified socket. Once the socket has been closed, it is not available for further networking use. If the socket has a channel, the channel is also closed. Syntax public void close () throws IOException Parameter NA Return NA Specified by The close()...
2 min read
Java method The getLocalPort() method of Java Socket class returns the local port number to which the specified socket is bound. If the socket was being closed, this method will return the connected port number after the socket is closed. Syntax public int getLocalPort() Parameter NA Return The getLocalPort () method...
2 min read
Java method The isInputShutdown () method of Java Socket class returns a Boolean value 'true' if the read-half of the socket connection has been closed, else it returns false. Syntax public boolean isInputShutdown () Parameter NA Return The isInputShutdown () method returns a Boolean value 'true' if the socket has been...
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 method The getTrafficClass() method of Java Socket class returns the traffic class or type-of-service in the IP header sent from the specified Socket. Syntax public int getTrafficClass () Throws SocketException Parameter NA Return The getTrafficClass () method returns the traffic class or type-of-service. Throws SocketException - if there occurs an error while...
2 min read
Java method The getOutputStream() method of Java Socket class returns an output stream for the given socket. If you close the returned OutputStream then it will close the linked socket. Syntax public OutputStream getOutputStream() throws IOException Parameter NA Return The getOutputStream() returns an output stream for writing bytes to this socket. Throws IOException-...
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
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
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