0

I have a server and i want to slow it down for some reasons and for experiments

long length = fileToSend.length();
            byte [] longBytes = new byte[8];
            ByteBuffer bbuffer = ByteBuffer.wrap(longBytes);
            bbuffer.putLong(length);
            connectionSocket.getOutputStream().write(longBytes);

            BufferedOutputStream bout = new BufferedOutputStream(connectionSocket.getOutputStream());
            BufferedInputStream bain = new BufferedInputStream(new FileInputStream(fileToSend));

            byte buffer [] = new byte [1024];
            int i = 0;
            while((i = bain.read(buffer, 0, 1024)) >= 0){

                bout.write(buffer, 0, i);

            }
            System.out.println("chunk sended");
            bout.close();
            bain.close();

i have some thoughts using something like thread sleep! but i don't now if it is sufficient and good solution! can someone guide me how to do that

Cbour
  • 49
  • 2
  • 9

1 Answers1

0

Using the thread.sleep(0.500); seems to work right! but is any other good solution to test it? or something else could be better?

Cbour
  • 49
  • 2
  • 9