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.

ChatModel.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 netz.model;
  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.ServerSocket;
  15. import java.net.Socket;
  16. import java.util.concurrent.ExecutorService;
  17. import java.util.concurrent.Executors;
  18. import java.util.concurrent.Flow;
  19. import java.util.concurrent.SubmissionPublisher;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import netz.controller.ChatController;
  23. import ohmlogger.OhmLogger;
  24. /**
  25. *
  26. * @author chris
  27. */
  28. public class ChatModel
  29. {
  30. private static Logger lg = OhmLogger.getLogger();
  31. private ServerRunnable serverRunnable;
  32. private ClientRunnable clientRunnable;
  33. // private ChatController controller;
  34. public ChatModel()
  35. {
  36. }
  37. public void startServer(int PORT, ChatController chatcontroller) throws IOException
  38. {
  39. ServerSocket sSocket = new ServerSocket(PORT);
  40. serverRunnable = new ServerRunnable(sSocket);
  41. chatcontroller.upddateStatus("Server: Warte auf Verbindung ...");
  42. }
  43. public void startClient(int PORT, String ip_adresse, ChatController chatcontroller) throws IOException
  44. {
  45. clientRunnable = new ClientRunnable(ip_adresse, PORT);
  46. chatcontroller.upddateStatus("Client: Warte auf Verbindung ...");
  47. }
  48. }
  49. //public class Bandit implements Runnable
  50. //{
  51. // private static Logger lg = OhmLogger.getLogger();
  52. //
  53. // private BanditInfo info;
  54. // private volatile boolean laufend;
  55. // private ExecutorService eService;
  56. // private SubmissionPublisher<BanditInfo> iPublisher;
  57. //
  58. // public Bandit(int nr)
  59. // {
  60. // info = new BanditInfo(nr);
  61. // synchronized(this)
  62. // {
  63. // laufend = true;
  64. // }
  65. // eService = Executors.newSingleThreadExecutor();
  66. // iPublisher = new SubmissionPublisher<>();
  67. //
  68. // }
  69. //
  70. // /**
  71. // * startet würfeln
  72. // */
  73. // public synchronized void start()
  74. // {
  75. // laufend = true;
  76. // eService.submit(this);
  77. // this.notifyAll();
  78. // lg.info("Thread startet");
  79. // }
  80. //
  81. // /**
  82. // * stopt würfeln
  83. // *
  84. // */
  85. // public void stop()
  86. // {
  87. // synchronized(this)
  88. // {
  89. // laufend = false;
  90. // }
  91. // lg.info("Thread stopt");
  92. // }
  93. //
  94. // public void addSubscription(Flow.Subscriber<BanditInfo> subscriber)
  95. // {
  96. // iPublisher.subscribe(subscriber);
  97. // }
  98. //
  99. // private synchronized void doWait()
  100. // {
  101. // try
  102. // {
  103. // this.wait();
  104. // } catch (InterruptedException ex)
  105. // {
  106. // Logger.getLogger(Bandit.class.getName()).log(Level.SEVERE, null, ex);
  107. // }
  108. // }
  109. //
  110. // @Override
  111. // public void run()
  112. // {
  113. //
  114. // while(true)
  115. // {
  116. //
  117. // while(!laufend)
  118. // this.doWait();
  119. //
  120. // try
  121. // {
  122. // Thread.sleep(10);
  123. // } catch (InterruptedException ex)
  124. // {
  125. // Logger.getLogger(Bandit.class.getName()).log(Level.SEVERE, null, ex);
  126. // }
  127. // info.setZaehlerWert((int)(Math.round(Math.random()*100) % 9) + 1);
  128. // iPublisher.submit(info);
  129. // }
  130. // }
  131. //}