src/main/java/org/tinyradius/util/RadiusServer.java
protected void listen(DatagramSocket s) {
        DatagramPacket packetIn = new DatagramPacket(new byte[RadiusPacket.MAX_PACKET_LENGTH], RadiusPacket.MAX_PACKET_LENGTH);
        while (true) {
            try {
                // receive packet
                try {
                    logger.trace("about to call socket.receive()");
                    s.receive(packetIn);
                    if (logger.isDebugEnabled()) {
                        logger.debug("receive buffer size = " + s.getReceiveBufferSize());
                    }
                }
                catch (SocketException se) {
                    if (closing) {
                        // end thread
                        logger.info("got closing signal - end listen thread");
                        return;
                    }
                    else {
                        // retry s.receive()
                        logger.error("SocketException during s.receive() -> retry", se);
                        continue;
                    }
                }

                // check client
                InetSocketAddress localAddress = (InetSocketAddress) s.getLocalSocketAddress();
                InetSocketAddress remoteAddress = new InetSocketAddress(packetIn.getAddress(), packetIn.getPort());
                String secret = getSharedSecret(remoteAddress);
                if (secret == null) {
                    if (logger.isInfoEnabled()) {
                        logger.info("ignoring packet from unknown client " + remoteAddress + " received on local address " + localAddress);
                    }
                    continue;
                }

                // parse packet
                RadiusPacket request = makeRadiusPacket(packetIn, secret);
                if (logger.isInfoEnabled()) {
                    logger.info("received packet from " + remoteAddress + " on local address " + localAddress + ": " + request);
                }

                // handle packet
                logger.trace("about to call RadiusServer.handlePacket()");
                RadiusPacket response = handlePacket(localAddress, remoteAddress, request, secret);

                // send response
                if (response != null) {
                    if (logger.isInfoEnabled()) {
                        logger.info("send response: " + response);
                    }
                    DatagramPacket packetOut = makeDatagramPacket(response, secret, remoteAddress.getAddress(), packetIn.getPort(), request);
                    s.send(packetOut);
                }
                else {
                    logger.info("no response sent");
                }
            }
            catch (SocketTimeoutException ste) {
                // this is expected behaviour
                logger.trace("normal socket timeout");
            }
            catch (IOException ioe) {
                // error while reading/writing socket
                logger.error("communication error", ioe);
            }
            catch (RadiusException re) {
                // malformed packet
                logger.error("malformed Radius packet", re);
            }
        }
    }
/**
     * Listens on the passed socket, blocks until stop() is called.
     *
     * @param s socket to listen on
     */
Listens on the passed socket, blocks until stop() is called.

@param s socket to listen on
Listens on the passed socket blocks until stop () is called . @param s socket to listen on
protected void listen(DatagramSocket s) {
        DatagramPacket packetIn = new DatagramPacket(new byte[RadiusPacket.MAX_PACKET_LENGTH], RadiusPacket.MAX_PACKET_LENGTH);
        while (true) {
            try {
                try {
                    logger.trace("about to call socket.receive()");
                    s.receive(packetIn);
                    if (logger.isDebugEnabled()) {
                        logger.debug("receive buffer size = " + s.getReceiveBufferSize());
                    }
                }
                catch (SocketException se) {
                    if (closing) {
                        logger.info("got closing signal - end listen thread");
                        return;
                    }
                    else {
                        logger.error("SocketException during s.receive() -> retry", se);
                        continue;
                    }
                }
                InetSocketAddress localAddress = (InetSocketAddress) s.getLocalSocketAddress();
                InetSocketAddress remoteAddress = new InetSocketAddress(packetIn.getAddress(), packetIn.getPort());
                String secret = getSharedSecret(remoteAddress);
                if (secret == null) {
                    if (logger.isInfoEnabled()) {
                        logger.info("ignoring packet from unknown client " + remoteAddress + " received on local address " + localAddress);
                    }
                    continue;
                }
                RadiusPacket request = makeRadiusPacket(packetIn, secret);
                if (logger.isInfoEnabled()) {
                    logger.info("received packet from " + remoteAddress + " on local address " + localAddress + ": " + request);
                }
                logger.trace("about to call RadiusServer.handlePacket()");
                RadiusPacket response = handlePacket(localAddress, remoteAddress, request, secret);
                if (response != null) {
                    if (logger.isInfoEnabled()) {
                        logger.info("send response: " + response);
                    }
                    DatagramPacket packetOut = makeDatagramPacket(response, secret, remoteAddress.getAddress(), packetIn.getPort(), request);
                    s.send(packetOut);
                }
                else {
                    logger.info("no response sent");
                }
            }
            catch (SocketTimeoutException ste) {
                logger.trace("normal socket timeout");
            }
            catch (IOException ioe) {
                logger.error("communication error", ioe);
            }
            catch (RadiusException re) {
                logger.error("malformed Radius packet", re);
            }
        }
    }
protected void listen ( DatagramSocket s ) { DatagramPacket packetIn = new DatagramPacket ( new byte [ RadiusPacket . MAX_PACKET_LENGTH ] , RadiusPacket . MAX_PACKET_LENGTH ) ; while ( true ) { try { try { logger . trace ( "about to call socket.receive()" ) ; s . receive ( packetIn ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "receive buffer size = " + s . getReceiveBufferSize ( ) ) ; } } catch ( SocketException se ) { if ( closing ) { logger . info ( "got closing signal - end listen thread" ) ; return ; } else { logger . error ( "SocketException during s.receive() -> retry" , se ) ; continue ; } } InetSocketAddress localAddress = ( InetSocketAddress ) s . getLocalSocketAddress ( ) ; InetSocketAddress remoteAddress = new InetSocketAddress ( packetIn . getAddress ( ) , packetIn . getPort ( ) ) ; String secret = getSharedSecret ( remoteAddress ) ; if ( secret == null ) { if ( logger . isInfoEnabled ( ) ) { logger . info ( "ignoring packet from unknown client " + remoteAddress + " received on local address " + localAddress ) ; } continue ; } RadiusPacket request = makeRadiusPacket ( packetIn , secret ) ; if ( logger . isInfoEnabled ( ) ) { logger . info ( "received packet from " + remoteAddress + " on local address " + localAddress + ": " + request ) ; } logger . trace ( "about to call RadiusServer.handlePacket()" ) ; RadiusPacket response = handlePacket ( localAddress , remoteAddress , request , secret ) ; if ( response != null ) { if ( logger . isInfoEnabled ( ) ) { logger . info ( "send response: " + response ) ; } DatagramPacket packetOut = makeDatagramPacket ( response , secret , remoteAddress . getAddress ( ) , packetIn . getPort ( ) , request ) ; s . send ( packetOut ) ; } else { logger . info ( "no response sent" ) ; } } catch ( SocketTimeoutException ste ) { logger . trace ( "normal socket timeout" ) ; } catch ( IOException ioe ) { logger . error ( "communication error" , ioe ) ; } catch ( RadiusException re ) { logger . error ( "malformed Radius packet" , re ) ; } } }
Listens on the passed socket, blocks until stop() is called.
Listens on the passed socket blocks until stop () is called .
// receive packet
 // end thread
 // retry s.receive()
 // check client
 // parse packet
 // handle packet
 // send response
 // this is expected behaviour
 // error while reading/writing socket
 // malformed packet
