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.

Kommunikationspartner.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 kommunikation.transmitter;
  7. import java.io.IOException;
  8. import java.io.ObjectInputStream;
  9. import java.io.ObjectOutputStream;
  10. import java.util.logging.Logger;
  11. import kommunikation.logger.OhmLogger;
  12. /**
  13. *
  14. * @author Alexander_Christoph
  15. */
  16. public abstract class Kommunikationspartner
  17. {
  18. protected static final Logger lg = OhmLogger.getLogger();
  19. protected int port;
  20. protected String ip;
  21. protected Object nachricht;
  22. protected Figur figur;
  23. protected ObjectInputStream in;
  24. protected ObjectOutputStream out;
  25. public Kommunikationspartner()
  26. {
  27. port = 35000;
  28. ip = "";
  29. }
  30. public abstract void verbinde();
  31. public void senden(Object nachricht)
  32. {
  33. try
  34. {
  35. out.writeObject(nachricht);
  36. }
  37. catch (IOException ex)
  38. {
  39. lg.severe(ex.toString());
  40. }
  41. lg.info("Grafik versendet");
  42. }
  43. public void empfangen()
  44. {
  45. try
  46. {
  47. lg.info("Warte auf Nachricht ...");
  48. nachricht = in.readObject();
  49. lg.info("Nachricht empfangen");
  50. }
  51. catch (IOException | ClassNotFoundException ex)
  52. {
  53. lg.severe(ex.toString());
  54. }
  55. }
  56. public Object getNachricht()
  57. {
  58. return nachricht;
  59. }
  60. public void setPort(int port)
  61. {
  62. this.port = port;
  63. lg.info("Port auf " + port + " gesetzt" );
  64. }
  65. public void setIp(String ip)
  66. {
  67. this.ip = ip;
  68. lg.info("Ip auf " + ip + " gesetzt" );
  69. }
  70. }