You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.8 KiB

  1. package verteiltesysteme.perf;
  2. import java.io.*;
  3. import java.net.*;
  4. import java.text.DateFormat;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7. class TCPPerfClient {
  8. public static void main(String argv[]) throws Exception {
  9. String hostname = "";
  10. int tcpPort = 36039;
  11. DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
  12. BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
  13. System.out.println("Bitte geben Sie die Server-Adresse ein: ");
  14. hostname = inFromUser.readLine();
  15. System.out.println("Bitte geben Sie die Anzahl zu �bertragender Megabytes ein: ");
  16. Long number = new Long(inFromUser.readLine());
  17. Socket clientSocket = new Socket(hostname, tcpPort);
  18. DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
  19. BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  20. long timestampStart = System.currentTimeMillis();
  21. System.out.println("Zeit vor Versand = " + timestampStart + " ms, " + df.format(new Date(timestampStart)));
  22. outToServer.writeBytes(number.toString() + "\n");
  23. char[] buffer = new char[1024 * 1024];
  24. long totalBytesReceived = 0;
  25. int charsRead = inFromServer.read(buffer);
  26. while (charsRead != -1)
  27. {
  28. totalBytesReceived += charsRead;
  29. charsRead = inFromServer.read(buffer);
  30. }
  31. long timestampEnd = System.currentTimeMillis();
  32. System.out.println("Zeit nach Empfang = " + timestampEnd + " ms, " + df.format(new Date(timestampEnd)));
  33. long duration = timestampEnd - timestampStart;
  34. System.out.println("Delay = " + duration + " ms");
  35. double seconds = (duration / 1000.0);
  36. double throughput = (totalBytesReceived / seconds);
  37. System.out.println("Rate = " + (long)throughput + " B/s");
  38. clientSocket.close();
  39. }
  40. }