/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package chatprogramm; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.Socket; import java.util.logging.Logger; /** * Builder Class * @author le */ public class Client { private static final Logger lg = Logger.getLogger("netz"); private static final int PORT = 35000; private static final String IP_ADRESSE = "127.0.0.1"; public Client() throws IOException { lg.info("Client: verbinde ..."); Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert! lg.info("Client: Verbindung hergestellt"); InputStream iStream = s.getInputStream(); OutputStream oStream = s.getOutputStream(); InputStreamReader isr = new InputStreamReader(iStream, "UTF-8"); OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8"); BufferedReader in = new BufferedReader(isr); //BufferedWriter out = new BufferedWriter(osr); PrintWriter out = new PrintWriter(osr); lg.info("Client: Stream initialisiert"); out.println("Hallo Du Server Du - ich bin der client"); out.flush(); // wirklich absenden!! lg.info("Client: Nachricht versendet"); String quittung = in.readLine(); // Achtung blockiert lg.info("Client: Quittung empfangen"); System.out.println("Client: Quittung EMPFANGEN - " + quittung); out.close(); in.close(); } /** * @param args the command line arguments */ public static void main(String[] args) { try { new Client(); } catch (IOException ex) { lg.severe(ex.toString()); } } }