Code example for DatagramSocket

Methods: close, getTrafficClass

0
        int IPTOS_LOWDELAY = 0x10;
        int[] ports = Support_PortManager.getNextPortsForUDP(2);
 
        new InetSocketAddress(InetAddress.getLocalHost(),
                ports[0]);
        DatagramSocket theSocket = new DatagramSocket(ports[1]);
 
        /* 
         * we cannot actually check that the values are set as if a platform 
         * does not support the option then it may come back unset even 
         * though we set it so just get the value to make sure we can get it 
         */ 
        int trafficClass = theSocket.getTrafficClass();
 
        theSocket.close();
        try { 
            theSocket.getTrafficClass();
            fail("SocketException was not thrown.");
        } catch(SocketException se) {
            //expected 
        } 
    }