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

3
  • As to whether Thread.sleep(L) is sufficient, why don't you try it? Apr 19, 2013 at 11:10
  • Please use a throttling proxy instead of changing your code to adhere to a bandwidth limitation. It is much easier to configure / re-configure. Apr 19, 2013 at 11:11
  • but if i want to do it inside my java server?
    – Cbour
    Apr 19, 2013 at 11:15

1 Answer 1

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.