src/main/java/org/tinyradius/packet/RadiusPacket.java
protected void encodePacket(OutputStream out, String sharedSecret, RadiusPacket request)
        throws IOException {
        // check shared secret
        if (sharedSecret == null || sharedSecret.length() == 0) {
            throw new RuntimeException("no shared secret has been set");
        }

        // check request authenticator
        if (request != null && request.getAuthenticator() == null) {
            throw new RuntimeException("request authenticator not set");
        }

        // request packet authenticator
        if (request == null) {
            // first create authenticator, then encode attributes
            // (User-Password attribute needs the authenticator)
            authenticator = createRequestAuthenticator(sharedSecret);
            encodeRequestAttributes(sharedSecret);
        }

        byte[] attributes = getAttributeBytes();
        int packetLength = RADIUS_HEADER_LENGTH + attributes.length;
        if (packetLength > MAX_PACKET_LENGTH) {
            throw new RuntimeException("packet too long");
        }

        // response packet authenticator
        if (request != null) {
            // after encoding attributes, create authenticator
            authenticator = createResponseAuthenticator(sharedSecret, packetLength, attributes, request.getAuthenticator());
        }
        else {
            // update authenticator after encoding attributes
            authenticator = updateRequestAuthenticator(sharedSecret, packetLength, attributes);
        }

        DataOutputStream dos = new DataOutputStream(out);
        dos.writeByte(getPacketType());
        dos.writeByte(getPacketIdentifier());
        dos.writeShort(packetLength);
        dos.write(getAuthenticator());
        dos.write(attributes);
        dos.flush();
    }
/**
     * Encodes this Radius packet and sends it to the specified output
     * stream.
     *
     * @param out          output stream to use
     * @param sharedSecret shared secret to be used to encode this packet
     * @param request      Radius request packet if this packet to be encoded
     *                     is a response packet, null if this packet is a request packet
     * @throws IOException      communication error
     * @throws RuntimeException if required packet data has not been set
     */
Encodes this Radius packet and sends it to the specified output
stream.


Encodes this Radius packet and sends it to the specified output stream .
protected void encodePacket(OutputStream out, String sharedSecret, RadiusPacket request)
        throws IOException {
        if (sharedSecret == null || sharedSecret.length() == 0) {
            throw new RuntimeException("no shared secret has been set");
        }
        if (request != null && request.getAuthenticator() == null) {
            throw new RuntimeException("request authenticator not set");
        }
        if (request == null) {
            authenticator = createRequestAuthenticator(sharedSecret);
            encodeRequestAttributes(sharedSecret);
        }
        byte[] attributes = getAttributeBytes();
        int packetLength = RADIUS_HEADER_LENGTH + attributes.length;
        if (packetLength > MAX_PACKET_LENGTH) {
            throw new RuntimeException("packet too long");
        }
        if (request != null) {
            authenticator = createResponseAuthenticator(sharedSecret, packetLength, attributes, request.getAuthenticator());
        }
        else {
            authenticator = updateRequestAuthenticator(sharedSecret, packetLength, attributes);
        }
        DataOutputStream dos = new DataOutputStream(out);
        dos.writeByte(getPacketType());
        dos.writeByte(getPacketIdentifier());
        dos.writeShort(packetLength);
        dos.write(getAuthenticator());
        dos.write(attributes);
        dos.flush();
    }
protected void encodePacket ( OutputStream out , String sharedSecret , RadiusPacket request ) throws IOException { if ( sharedSecret == null || sharedSecret . length ( ) == 0 ) { throw new RuntimeException ( "no shared secret has been set" ) ; } if ( request != null && request . getAuthenticator ( ) == null ) { throw new RuntimeException ( "request authenticator not set" ) ; } if ( request == null ) { authenticator = createRequestAuthenticator ( sharedSecret ) ; encodeRequestAttributes ( sharedSecret ) ; } byte [ ] attributes = getAttributeBytes ( ) ; int packetLength = RADIUS_HEADER_LENGTH + attributes . length ; if ( packetLength > MAX_PACKET_LENGTH ) { throw new RuntimeException ( "packet too long" ) ; } if ( request != null ) { authenticator = createResponseAuthenticator ( sharedSecret , packetLength , attributes , request . getAuthenticator ( ) ) ; } else { authenticator = updateRequestAuthenticator ( sharedSecret , packetLength , attributes ) ; } DataOutputStream dos = new DataOutputStream ( out ) ; dos . writeByte ( getPacketType ( ) ) ; dos . writeByte ( getPacketIdentifier ( ) ) ; dos . writeShort ( packetLength ) ; dos . write ( getAuthenticator ( ) ) ; dos . write ( attributes ) ; dos . flush ( ) ; }
Encodes this Radius packet and sends it to the specified output
 stream.
Encodes this Radius packet and sends it to the specified output stream .
// check shared secret
 // check request authenticator
 // request packet authenticator
 // first create authenticator, then encode attributes
 // (User-Password attribute needs the authenticator)
 // response packet authenticator
 // after encoding attributes, create authenticator
 // update authenticator after encoding attributes
