Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a25f1617c8 | ||
|
|
72b3888984 | ||
|
|
109123a241 | ||
|
|
7cd668f8ce |
@@ -41,8 +41,9 @@ public class CommandController implements ActionListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerCommands(){
|
public void registerCommands(){
|
||||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view));
|
CommandSend commandSend = new CommandSend(view);
|
||||||
invoker.addCommand(view.getTfNachricht(), new CommandSend());
|
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view, commandSend));
|
||||||
|
invoker.addCommand(view.getTfNachricht(), commandSend);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,10 +9,35 @@ package ChatProgramm.controller;
|
|||||||
*
|
*
|
||||||
* @author ahren
|
* @author ahren
|
||||||
*/
|
*/
|
||||||
class Nachricht
|
public class Nachricht
|
||||||
{
|
{
|
||||||
public Nachricht()
|
private String nachricht;
|
||||||
|
//private int id;
|
||||||
|
|
||||||
|
public Nachricht(String nachricht)
|
||||||
{
|
{
|
||||||
|
this.setNachricht(nachricht);
|
||||||
|
//this.id = id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the id
|
||||||
|
*/
|
||||||
|
// public int getId() {
|
||||||
|
// return id;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the nachricht
|
||||||
|
*/
|
||||||
|
public String getNachricht() {
|
||||||
|
return nachricht;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNachricht(String nachricht) {
|
||||||
|
this.nachricht = nachricht;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ChatProgramm.controller;
|
package ChatProgramm.controller;
|
||||||
|
|
||||||
|
import ChatProgramm.view.ChatView;
|
||||||
import java.util.concurrent.Flow;
|
import java.util.concurrent.Flow;
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
import java.util.concurrent.Flow.Subscriber;
|
||||||
|
|
||||||
@@ -12,30 +12,32 @@ import java.util.concurrent.Flow.Subscriber;
|
|||||||
*
|
*
|
||||||
* @author ahren
|
* @author ahren
|
||||||
*/
|
*/
|
||||||
public class ReceiveAdapter implements Subscriber<Nachricht>
|
public class ReceiveAdapter implements Subscriber<Nachricht> {
|
||||||
{
|
|
||||||
public ReceiveAdapter()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
private ChatView view;
|
||||||
|
private Flow.Subscription subscription;
|
||||||
|
|
||||||
|
public ReceiveAdapter(ChatView view) {
|
||||||
|
this.view = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Flow.Subscription subscription)
|
public void onSubscribe(Flow.Subscription subscription) {
|
||||||
{
|
this.subscription = subscription;
|
||||||
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(Nachricht item)
|
public void onNext(Nachricht item) {
|
||||||
{
|
view.getTxtChat().setText(item.getNachricht());
|
||||||
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable throwable)
|
public void onError(Throwable throwable) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete()
|
public void onComplete() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,19 @@ public class CommandConnect implements CommandInterface
|
|||||||
private JDialog dialogFenster;
|
private JDialog dialogFenster;
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
|
||||||
public CommandConnect(ChatView view)
|
private CommandSend commandSend;
|
||||||
|
|
||||||
|
private ChatView view;
|
||||||
|
|
||||||
|
public CommandConnect(ChatView view, CommandInterface value)
|
||||||
{
|
{
|
||||||
rBtnServer = view.getBtnServer();
|
rBtnServer = view.getBtnServer();
|
||||||
rBtnClient = view.getBtnClient();
|
rBtnClient = view.getBtnClient();
|
||||||
dialogFenster = view.getjDialog1();
|
dialogFenster = view.getjDialog1();
|
||||||
|
|
||||||
|
commandSend = (CommandSend) value;
|
||||||
|
|
||||||
|
this.view = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,7 +47,7 @@ public class CommandConnect implements CommandInterface
|
|||||||
if(rBtnServer.isSelected()){
|
if(rBtnServer.isSelected()){
|
||||||
lg.info("Server ausgewählt");
|
lg.info("Server ausgewählt");
|
||||||
try {
|
try {
|
||||||
new Server();
|
commandSend.transmitterInterface = new Server(view);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
lg.info("Die Verbindung zum Server ist Fehlgeschlagen");
|
||||||
}
|
}
|
||||||
@@ -48,7 +56,7 @@ public class CommandConnect implements CommandInterface
|
|||||||
if(rBtnClient.isSelected()){
|
if(rBtnClient.isSelected()){
|
||||||
lg.info("Client ausgewählt");
|
lg.info("Client ausgewählt");
|
||||||
try {
|
try {
|
||||||
new Client();
|
commandSend.transmitterInterface = new Client(view);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
lg.info("Die Verbindung zum Client ist Fehlgeschlagen");
|
||||||
|
|
||||||
|
|||||||
@@ -5,20 +5,47 @@
|
|||||||
|
|
||||||
package ChatProgramm.controller.commands;
|
package ChatProgramm.controller.commands;
|
||||||
|
|
||||||
|
import ChatProgramm.controller.Nachricht;
|
||||||
|
import ChatProgramm.model.Client;
|
||||||
|
import ChatProgramm.model.Server;
|
||||||
|
import ChatProgramm.model.Transmitter;
|
||||||
|
import ChatProgramm.model.TransmitterInterface;
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ahren
|
* @author ahren
|
||||||
*/
|
*/
|
||||||
public class CommandSend implements CommandInterface
|
public class CommandSend implements CommandInterface
|
||||||
{
|
{
|
||||||
public CommandSend()
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
{
|
|
||||||
|
|
||||||
|
private ChatView view;
|
||||||
|
public TransmitterInterface transmitterInterface;
|
||||||
|
private JTextField eingabeFeld;
|
||||||
|
|
||||||
|
public Server server;
|
||||||
|
public Client client;
|
||||||
|
|
||||||
|
public CommandSend(ChatView view)
|
||||||
|
{
|
||||||
|
this.view = view;
|
||||||
|
this.eingabeFeld = view.getTfNachricht();
|
||||||
|
transmitterInterface = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
|
if(transmitterInterface != null && !eingabeFeld.getText().isEmpty()){
|
||||||
|
transmitterInterface.send(new Nachricht(eingabeFeld.getText()));
|
||||||
|
eingabeFeld.setText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,14 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import ChatProgramm.util.OhmLogger;
|
||||||
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.ServerSocket;
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
@@ -22,17 +18,13 @@ import java.util.logging.*;
|
|||||||
*/
|
*/
|
||||||
public class Client extends Transmitter {
|
public class Client extends Transmitter {
|
||||||
|
|
||||||
private static Logger lg = Logger.getLogger("netz");
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
|
||||||
private Socket socket;
|
|
||||||
private BufferedReader reader;
|
|
||||||
private PrintWriter writer;
|
|
||||||
|
|
||||||
private static final int PORT = 35000; //lt. iana port > 2¹⁵
|
public Client(ChatView view) throws IOException {
|
||||||
private static final String IP = "127.0.0.1";
|
super(view);
|
||||||
|
|
||||||
public Client() throws IOException {
|
|
||||||
connect();
|
connect();
|
||||||
|
initIO();
|
||||||
|
|
||||||
// out.println("Hallo Du Server - ich bin ein Client");
|
// out.println("Hallo Du Server - ich bin ein Client");
|
||||||
// out.flush();
|
// out.flush();
|
||||||
@@ -48,16 +40,6 @@ public class Client extends Transmitter {
|
|||||||
// s.close();
|
// s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param args the command line arguments
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
new Client();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect() throws IOException {
|
public void connect() throws IOException {
|
||||||
@@ -66,21 +48,10 @@ public class Client extends Transmitter {
|
|||||||
socket = new Socket(IP, PORT);
|
socket = new Socket(IP, PORT);
|
||||||
lg.info("Client: Verbindung aufgebaut");
|
lg.info("Client: Verbindung aufgebaut");
|
||||||
|
|
||||||
lg.info("Client: initialisiere reader und writer");
|
|
||||||
InputStream is = socket.getInputStream();
|
|
||||||
OutputStream os = socket.getOutputStream();
|
|
||||||
|
|
||||||
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
|
||||||
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
|
||||||
|
|
||||||
reader = new BufferedReader(isr);
|
|
||||||
writer = new PrintWriter(osr);
|
|
||||||
lg.info("Client: Initialisierung abgeschlossen");
|
|
||||||
|
|
||||||
lg.info("Client: warte auf Nachricht");
|
|
||||||
|
|
||||||
} catch (java.io.InterruptedIOException e) {
|
} catch (java.io.InterruptedIOException e) {
|
||||||
lg.warning("Timeout" + "(" + timeout / 1000 + "s)");
|
lg.warning("Timeout" + "(" + timeout / 1000 + "s)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import ChatProgramm.model.Transmitter;
|
import ChatProgramm.model.Transmitter;
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -13,57 +15,45 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.Flow;
|
||||||
|
import java.util.concurrent.SubmissionPublisher;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder Class
|
* Builder Class
|
||||||
|
*
|
||||||
* @author le
|
* @author le
|
||||||
*/
|
*/
|
||||||
public class Server extends Transmitter
|
public class Server extends Transmitter {
|
||||||
{
|
|
||||||
private static Logger lg = Logger.getLogger("netz");
|
|
||||||
|
|
||||||
private Socket socket;
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
private BufferedReader reader;
|
|
||||||
private PrintWriter writer;
|
|
||||||
|
|
||||||
private static final int PORT = 35000; //lt. iana port > 2¹⁵
|
|
||||||
|
|
||||||
public void connect() throws IOException
|
@Override
|
||||||
{
|
public void connect() throws IOException {
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
ServerSocket sSocket = new ServerSocket(PORT);
|
ServerSocket sSocket = new ServerSocket(PORT);
|
||||||
sSocket.setSoTimeout(timeout);
|
sSocket.setSoTimeout(timeout);
|
||||||
lg.info("Server: warte auf Verbindung");
|
lg.info("Server: warte auf Verbindung");
|
||||||
socket = sSocket.accept();
|
socket = sSocket.accept();
|
||||||
lg.info("Server: Verbindung akzeptiert");
|
lg.info("Server: Verbindung akzeptiert");
|
||||||
|
|
||||||
lg.info("Server: initialisiere reader und writer");
|
} catch (java.io.InterruptedIOException e) {
|
||||||
InputStream is = socket.getInputStream();
|
lg.warning("Timeout" + "(" + timeout / 1000 + "s)");
|
||||||
OutputStream os = socket.getOutputStream();
|
|
||||||
|
|
||||||
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
|
||||||
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
|
||||||
|
|
||||||
reader = new BufferedReader(isr);
|
|
||||||
writer = new PrintWriter(osr);
|
|
||||||
lg.info("Server: Initialisierung abgeschlossen");
|
|
||||||
|
|
||||||
lg.info("Server: warte auf Nachricht");
|
|
||||||
|
|
||||||
}
|
|
||||||
catch ( java.io.InterruptedIOException e )
|
|
||||||
{
|
|
||||||
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public Server() throws IOException
|
|
||||||
{
|
|
||||||
|
|
||||||
|
public Server(ChatView view) throws IOException {
|
||||||
|
super(view);
|
||||||
connect();
|
connect();
|
||||||
|
initIO();
|
||||||
|
|
||||||
// String nachricht = in.readLine(); // ACHTUNG blockiert
|
// String nachricht = in.readLine(); // ACHTUNG blockiert
|
||||||
// lg.info("Server: Nachricht erhalten");
|
// lg.info("Server: Nachricht erhalten");
|
||||||
@@ -79,18 +69,6 @@ public class Server extends Transmitter
|
|||||||
// s.close();
|
// s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param args the command line arguments
|
|
||||||
*/
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
new Server();
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
import ChatProgramm.controller.Nachricht;
|
||||||
|
import ChatProgramm.controller.ReceiveAdapter;
|
||||||
|
import ChatProgramm.util.OhmLogger;
|
||||||
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@@ -11,11 +16,12 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.ServerSocket;
|
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Flow;
|
import java.util.concurrent.Flow;
|
||||||
import java.util.concurrent.Flow.Subscriber;
|
import java.util.concurrent.Flow.Subscriber;
|
||||||
|
import java.util.concurrent.SubmissionPublisher;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -23,23 +29,42 @@ import java.util.logging.Logger;
|
|||||||
*
|
*
|
||||||
* @author ahren
|
* @author ahren
|
||||||
*/
|
*/
|
||||||
public abstract class Transmitter implements Runnable, Subscriber<String> {
|
public abstract class Transmitter implements Runnable, Subscriber<Nachricht>, TransmitterInterface {
|
||||||
|
|
||||||
static final int timeout = 60000;
|
static final int timeout = 30000;
|
||||||
private static final int PORT = 35000;
|
protected static final int PORT = 35000;
|
||||||
|
protected static final String IP = "127.0.0.1";
|
||||||
|
|
||||||
private static Logger lg = Logger.getLogger("netz");
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
|
||||||
private Socket socket;
|
protected Socket socket;
|
||||||
private BufferedReader reader;
|
protected BufferedReader reader;
|
||||||
private PrintWriter writer;
|
protected PrintWriter writer;
|
||||||
|
|
||||||
public Transmitter() {
|
private SubmissionPublisher<Nachricht> textPublisher;
|
||||||
|
private ExecutorService eService;
|
||||||
|
private boolean laufend = false;
|
||||||
|
|
||||||
|
private ChatView view;
|
||||||
|
|
||||||
|
private ReceiveAdapter receiveAdapter;
|
||||||
|
|
||||||
|
public Transmitter(ChatView view) {
|
||||||
|
socket = new Socket();
|
||||||
|
eService = null;
|
||||||
|
this.view = view;
|
||||||
|
textPublisher = new SubmissionPublisher<>();
|
||||||
|
|
||||||
|
receiveAdapter = new ReceiveAdapter(view);
|
||||||
|
addWertSubscription(receiveAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void connect() throws IOException;
|
public abstract void connect() throws IOException;
|
||||||
|
|
||||||
|
public void addWertSubscription(Subscriber<Nachricht> subscriber) {
|
||||||
|
textPublisher.subscribe(subscriber);
|
||||||
|
}
|
||||||
|
|
||||||
public void initIO() {
|
public void initIO() {
|
||||||
try {
|
try {
|
||||||
lg.info("Initialisiere reader und writer");
|
lg.info("Initialisiere reader und writer");
|
||||||
@@ -51,19 +76,72 @@ public abstract class Transmitter implements Runnable, Subscriber<String> {
|
|||||||
|
|
||||||
reader = new BufferedReader(isr);
|
reader = new BufferedReader(isr);
|
||||||
writer = new PrintWriter(osr);
|
writer = new PrintWriter(osr);
|
||||||
lg.info("Server: Initialisierung abgeschlossen");
|
lg.info("Initialisierung abgeschlossen");
|
||||||
|
|
||||||
lg.info("Server: warte auf Nachricht");
|
start();
|
||||||
|
|
||||||
} catch (UnsupportedEncodingException ex) {
|
|
||||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void start(){
|
||||||
|
synchronized (this){
|
||||||
|
laufend = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eService == null){
|
||||||
|
eService = Executors.newSingleThreadExecutor();
|
||||||
|
eService.execute(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
lg.info("Starte Chat");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(Nachricht nachricht) {
|
||||||
|
lg.info("Nachricht wird gesendet");
|
||||||
|
writer.println(nachricht.getNachricht());
|
||||||
|
writer.flush();
|
||||||
|
|
||||||
|
lg.info("Nachricht wird angezeigt");
|
||||||
|
textPublisher.submit(nachricht);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Nachricht receive(){
|
||||||
|
Nachricht nachricht = new Nachricht("");
|
||||||
|
try {
|
||||||
|
String txtNachricht = reader.readLine();
|
||||||
|
if(!txtNachricht.isEmpty()){
|
||||||
|
lg.info("Nachricht erhalten");
|
||||||
|
nachricht.setNachricht(txtNachricht);
|
||||||
|
return nachricht;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return nachricht;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
lg.info("Warte auf Nachricht");
|
||||||
|
if(laufend) {
|
||||||
|
Nachricht eingehendeNachricht = receive();
|
||||||
|
|
||||||
|
if(!eingehendeNachricht.getNachricht().isEmpty()){
|
||||||
|
textPublisher.submit(eingehendeNachricht);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,11 +149,6 @@ public abstract class Transmitter implements Runnable, Subscriber<String> {
|
|||||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNext(String item) {
|
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable throwable) {
|
public void onError(Throwable throwable) {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||||
@@ -86,4 +159,9 @@ public abstract class Transmitter implements Runnable, Subscriber<String> {
|
|||||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNext(Nachricht item) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
import ChatProgramm.controller.Nachricht;
|
||||||
|
|
||||||
|
public interface TransmitterInterface{
|
||||||
|
public void send(Nachricht nachricht);
|
||||||
|
public Nachricht receive();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user