Online Java Compiler By
JavaTpoint.com
import java.io.IOException; import java.net.*; public class JavaSocketSetTraffiClassExample2 { public static void main(String[] args) throws IOException { //calling the constructor of the socket class Socket socket = new Socket(); //integer value for the bitset. //tc should be in the range from 0 to 255(0<=tc<=255) else an IllegalArgumentException will be thrown int tc=-98; //setTrafficClass() sets the traffic class or type-of-service in the IP header for packets sent from the specified socket socket.setTrafficClass(tc); //getTcpNoDelay() returns the setting for SO_TIMEOUT option System.out.println("Traffic class: "+socket.getTrafficClass()); } }
Output