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.

Client.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package chatprogramm;
  7. import java.io.BufferedReader;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.InputStreamReader;
  11. import java.io.OutputStream;
  12. import java.io.OutputStreamWriter;
  13. import java.io.PrintWriter;
  14. import java.net.Socket;
  15. import java.util.logging.Logger;
  16. /**
  17. * Builder Class
  18. * @author le
  19. */
  20. public class Client
  21. {
  22. private static final Logger lg = Logger.getLogger("netz");
  23. private static final int PORT = 35000;
  24. private static final String IP_ADRESSE = "127.0.0.1";
  25. public Client() throws IOException
  26. {
  27. lg.info("Client: verbinde ...");
  28. Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert!
  29. lg.info("Client: Verbindung hergestellt");
  30. InputStream iStream = s.getInputStream();
  31. OutputStream oStream = s.getOutputStream();
  32. InputStreamReader isr = new InputStreamReader(iStream, "UTF-8");
  33. OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8");
  34. BufferedReader in = new BufferedReader(isr);
  35. //BufferedWriter out = new BufferedWriter(osr);
  36. PrintWriter out = new PrintWriter(osr);
  37. lg.info("Client: Stream initialisiert");
  38. out.println("Hallo Du Server Du - ich bin der client");
  39. out.flush(); // wirklich absenden!!
  40. lg.info("Client: Nachricht versendet");
  41. String quittung = in.readLine(); // Achtung blockiert
  42. lg.info("Client: Quittung empfangen");
  43. System.out.println("Client: Quittung EMPFANGEN - " + quittung);
  44. out.close();
  45. in.close();
  46. }
  47. /**
  48. * @param args the command line arguments
  49. */
  50. public static void main(String[] args)
  51. {
  52. try
  53. {
  54. new Client();
  55. }
  56. catch (IOException ex)
  57. {
  58. lg.severe(ex.toString());
  59. }
  60. }
  61. }