double fileSizeKB = (fileByteArray.length) / 1024;
        double transferTime = timer.getTimeElapsed() / 1000;
        double fileSizeMB = fileSizeKB/1000;
        double throughput = fileSizeMB/transferTime;




        System.out.println("The size of the File was "+fileSizeMB+ " MegaBytes");
        System.out.println("Time for transfer was " +timer.getTimeElapsed()/1000+ " Seconds");
        System.out.printf("Throughput was %.2f MB Per Second\n",+throughput);
        System.out.println("Number of retransmissions: " + retransmissionCounter);  

        byte[] statMessage = new byte[32];
        statMessage[0]= (byte) throughput;
        statMessage[1]=(byte) fileSizeMB;
        statMessage[2]=(byte) transferTime;


        DatagramPacket statPacket = new DatagramPacket(statMessage,statMessage.length,address,port);
        socket.send(statPacket);

        System.out.println(statMessage[0]);
        System.out.println(statMessage[1]);
        System.out.println(statMessage[2]);
        socket.close();

The program sends a file using UDP reliably, however, at the end of file transfer I want to print some statistics both sides, client is fine, but when I try send those statistics to the server, although they do send, for example, throughput may be 1.4 mbps, but it rounds down to 1 mbps...why is this!?

Because bytes are integer values. Doubles are 8 byte floating point values. When you assign a float value to a byte it's rounded down to the nearest integer value.
You also have a problem if the value is >127, becuase that's the largest value a byte can hold.

Either way, the answer is to use more than 1 byte to send the value.
You can use an nio ByteBuffer to convert doubles etc to byte arrays abd back again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.