All pastes #83614 Raw Edit

tcp

public java v1 · immutable
·published 2006-07-09 22:43 UTC
rendered paste body
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.Inet4Address;import java.net.InetAddress;import java.net.Socket;import java.net.UnknownHostException;import java.math.*;public class Aufgabe1Client {static int counter=0;static Socket clientSocket;static PrintWriter out;static BufferedReader in;static final int wiederholungen=10000;static float values[];  static float delta_squared[];  static Timer timer1 = new Timer();	static public void main(String[]args){		values = new float[wiederholungen];		delta_squared = new float[wiederholungen];				try {			//clientSocket = new Socket("localhost",4400);			clientSocket = new Socket(InetAddress.getByName("SUPAKISTE") ,4400);		} catch (UnknownHostException e) {			System.out.println("Kenne den Host nicht!");			e.printStackTrace();		} catch (IOException e) {			System.out.println("IO Problem. Ist Port 4400 verfügbar?");			e.printStackTrace();		}		try {			out = new PrintWriter(clientSocket.getOutputStream(), true);			in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));		} catch (IOException e) {			System.out.println("IO Problem im PrintWriter");			e.printStackTrace();		}				System.out.println("Starte Timer..");		//timer1.start();		long start,stop,zeit=0;		System.out.println(" " + System.currentTimeMillis());		for (int i = 0; i < wiederholungen; i++ ){			try {				start = System.nanoTime();				out.println("Test");				in.readLine();				stop = System.nanoTime();				values[counter]=(stop - start);				zeit+= (stop - start);				counter++;			//	System.out.println("Echo is:" + in.readLine());			} catch (IOException e) {				System.out.println("Problem sending message or catching the echo!");				e.printStackTrace();							}					}		try {			out.close();			in.close();			clientSocket.close();  		} catch (IOException e) {			e.printStackTrace();		}		float ew = zeit;		float varianz=0;		ew /= wiederholungen ; 		for (int i = 0; i < wiederholungen;i++){			delta_squared[i] = (ew - values[i])*(ew - values[i]); //Quadratische Abweichung bestimmen			varianz+= delta_squared[i];			System.out.println("message "+ i + " and echo took: " + values[i] / 1000000+"ms "+ 					" |||| Die Quadratische Abweichung vom " +					"Erwartungswert beträgt " + delta_squared[i] / 1000000*1000000 +"ms^2");		}		varianz/=wiederholungen;		System.out.println(counter + " Echos empfangen, " + "es hat " + zeit /1000000 + 				" Milliseconds gedauert" );		System.out.println("Erwartungswert = " + ew / 1000000 +"ms");		System.out.println("Die Varianz = " + (varianz / 1000000*1000000) +"ms^2");		System.out.println("Die Standardabweichung = " + Math.sqrt(varianz)/1000000 +"ms");											}}