Code example for DatagramPacket

Methods: getDatasetLength

     * 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);
     * 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());
Connect your IDE to all the code out there  Get Codota for Java