Java Socket getTrafficClass() 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

Parameter

NA

Return

The getTrafficClass () method returns the traffic class or type-of-service.

Throws

SocketException - if there occurs an error while obtaining the traffic class or type-of-service value.

Example 1

Test it Now

Output:

Traffic class: 88

Example 2

Test it Now

Output:

Exception in thread "main" java.net.SocketException: Socket is closed
	at java.net.Socket.setTrafficClass(Socket.java:1380)
	at com.javaTpoint.JavaSocketGetTrafficClassExample3.main(JavaSocketGetTrafficClassExample3.java:13)




Latest Courses