Java Socket setTrafficClass() methodThe 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 1Test it NowOutput: Traffic class: 98 Example 2Test it NowOutput: Exception in thread "main" java.lang.IllegalArgumentException: tc is not in range 0 -- 255 at java.net.Socket.setTrafficClass(Socket.java:1377) at com.javaTpoint.JavaSocketSetTrafficClassExample2.main(JavaSocketSetTrafficClassExample2.java:13) Example 3Test it NowOutput: Exception in thread "main" java.net.SocketException: Socket is closed at java.net.Socket.setTrafficClass(Socket.java:1380) at com.javaTpoint.JavaSocketSetTrafficClassExample3.main(JavaSocketSetTrafficClassExample3.java:15) Next TopicJava Socket Class |
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