public void run() {
        // Make the run method a private matter
        if(receiverThread != Thread.currentThread()) return;

        try {
            initializeLine();

            int frameSizeInBytes = format.getFrameSize();
            int bufferLengthInFrames = line.getBufferSize() / AudioStreamUDP.BUFFER_VS_FRAMES_RATIO;
            int bufferLengthInBytes = bufferLengthInFrames * frameSizeInBytes;
            if(AudioStreamUDP.DEBUG) {
                System.out.println("bufferLengthInFrames = " + bufferLengthInFrames);
                System.out.println("bufferLengthInBytes = " + bufferLengthInBytes);
            }
            byte[] data = new byte[bufferLengthInBytes];
            DatagramPacket packet = new DatagramPacket(data, bufferLengthInBytes);
            int numBytesRead = 0;

            line.start();
            int packets = 0;
            while (receiverThread != null) {
                socket.receive(packet);
                // Who's the sender?
                if(remoteHost.equals(packet.getAddress())) {
                    numBytesRead = packet.getLength();
                    if(AudioStreamUDP.DEBUG) {
                        System.out.println("Received bytes = " + numBytesRead + ", packets = " + packets++);
                    }
                    int numBytesRemaining = numBytesRead;
                    while (numBytesRemaining > 0 ) {
                        numBytesRemaining -= line.write(data, 0, numBytesRemaining);
                    }
                }
            }
        }
        catch(SocketTimeoutException ste) {
            System.out.println("Receive call timed out");
        }
        catch(SocketException se) {
            System.out.println("Receiver socket is closed");
            // If the thread is blocked in a receive call, an exception is thrown when
            // the socket is closed, causing the thread to unblock.
        }
        catch(Exception e) {
            e.printStackTrace();
        }
        finally {
            this.cleanUp();
        }
    }