daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.net.*;
  3. import java.util.Date;
  4.  
  5. public class Main {
  6.     public static void main(String argv[]) throws Exception {
  7.         String clientSentence;
  8.         String capitalizedSentence;
  9.         ServerSocket welcomeSocket = new ServerSocket(3010);
  10.         Integer cycles = 10;
  11.  
  12.         long elapsedTime = 0L;
  13.         int total_bytes=0;
  14.         long startTime=0;
  15.         boolean once=true;
  16.         int interval=60;
  17.         while (elapsedTime < interval*1000) {
  18.             //perform db poll/check
  19.             cycles--;
  20.             Socket connectionSocket = welcomeSocket.accept();
  21.             BufferedReader inFromClient =
  22.                     new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
  23.             DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
  24.             clientSentence = inFromClient.readLine();
  25.             if(once)startTime = System.currentTimeMillis();
  26.             once=false;
  27.             System.out.println("Received: " + clientSentence);
  28.             total_bytes=total_bytes+1024;
  29.             elapsedTime = (new Date()).getTime() - startTime;
  30.         }
  31.  
  32.         System.out.println("Total Bytes Recvd: "+ total_bytes );
  33.         System.out.println("Average Throughput: "+ total_bytes/interval + " B/s\t"+total_bytes*8/interval+" b/s");
  34. /*
  35.  
  36.         while (cycles>0) {
  37.             cycles--;
  38.             Socket connectionSocket = welcomeSocket.accept();
  39.             BufferedReader inFromClient =
  40.                     new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
  41.             DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
  42.             clientSentence = inFromClient.readLine();
  43.             System.out.println("Received: " + clientSentence);
  44.             capitalizedSentence = clientSentence.toUpperCase() + '\n';
  45.             //outToClient.writeBytes(capitalizedSentence);
  46.         }*/
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top