[英]How do i make my game not speed up/slow down depending on the fps in java?
[英]how to slow down the speed of buffer sending java
我有一台服務器,出於某些原因和實驗原因,我希望將其速度降低
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();
我有一些想法,例如使用線程睡眠! 但是我現在不知道它是否足夠和好的解決方案! 有人可以指導我怎么做嗎
使用thread.sleep(0.500); 似乎工作正常! 但是還有其他好的測試方法嗎? 還是有其他更好的辦法?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.