Code example for DatagramPacket

Methods: getDatasetLength

0
    /** 
     * Converts a given String into a datagram packet. 
     */ 
    static void stringToPacket(String s, DatagramPacket packet) {
        byte[] bytes = s.getBytes();
        System.arraycopy(bytes, 0, packet.getData(), 0, bytes.length);
        packet.setLength(bytes.length);
    } 
 
    /** 
     * Implements the main part of the Datagram test. 
     */ 
    public void testDatagram() throws Exception { 
 
        Reflector reflector = null;
        DatagramSocket socket = null;
 
        try { 
            // Setup the reflector, so we have a partner to send to 
            reflector = new Reflector(1234, InetAddress.getLocalHost());
Stop searching for code, let great code find you!  Add Codota to your java IDE