Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketGetTrafficClassExample2 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //closing the socket socket.close(); int tc=89; //sets the traffic class for this socket socket.setTrafficClass(tc); //getTrafficClass() returns the traffic class //will return an exception, as the socket is already closed System.out.println("Traffic class: "+socket.getTrafficClass()); } }
Output