Java Socket setTrafficClass() method25 Mar 2025 | 2 min read The setTrafficClass() method of Java Socket class sets the traffic class or type-of-service in the IP header for packets sent from the specified socket. The parameter (tc) should be in the range from 0 to 255(0<=tc<=255) else an IllegalArgumentException will be thrown. SyntaxParameterThe parameter 'tc' represents an integer value for the bitset. ReturnNA ThrowsSocketException - if an error is there in the setting of the traffic class or type-of-service. Example 1Output: Traffic class: 98 Example 2Output: Exception in thread "main" java.lang.IllegalArgumentException: tc is not in range 0 -- 255 at java.net.Socket.setTrafficClass(Socket.java:1377) at com.tpointtech.JavaSocketSetTrafficClassExample2.main(JavaSocketSetTrafficClassExample2.java:13) Example 3Output: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.setTrafficClass(Socket.java:1380) at com.tpointtech.JavaSocketSetTrafficClassExample3.main(JavaSocketSetTrafficClassExample3.java:15) Next TopicJava Socket Class |
Java method The isOutputShutdown () 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 boolean isOutputShutdown () Parameter NA Return The isOutputShutdown () method would return a Boolean value 'true' if the output...
3 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 Socket setSendBufferSize () method 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. Syntax public void setSendBufferSize (int size) throws SocketException Parameter The parameter 'size' represents the size to which the...
2 min read
Java Socket getReuseAddress () method The getReuseAddress () method of Java Socket class tests whether the SO_REUSEADDR option is enabled or not. It throws SocketException if finds an error in the underlying protocol, such as a TCP error. Syntax public boolean getReuseAddress() Parameter NA Return The getReuseAddress () method returns a...
2 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 setReceiveBufferSize() method of Java Socket class sets the SO_RCVBUF option to the given value for the specified socket. The buffer size should be greater than zero else, it will throw an IllegalArgumentException. Syntax public void setReceiveBufferSize (int size) throws SocketException Parameter The parameter 'size' represents the...
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 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 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 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
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