|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /*
- * 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 netz;
-
- 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;
- import ohmlogger.OhmLogger;
-
- /**
- * Builder Class
- * @author le
- */
- public class Client
- {
- private static Logger lg = OhmLogger.getLogger();
- 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());
- }
- }
- }
|