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

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