Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0e1bd16f3 | ||
|
|
de596fad8c | ||
|
|
e617b11f86 | ||
|
|
efecd40ab4 | ||
|
|
3604e5469e | ||
|
|
0548fee0a4 | ||
|
|
96ac335267 |
@@ -6,7 +6,6 @@
|
|||||||
package ChatProgramm;
|
package ChatProgramm;
|
||||||
|
|
||||||
import ChatProgramm.controller.CommandController;
|
import ChatProgramm.controller.CommandController;
|
||||||
import ChatProgramm.model.Transmitter;
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
@@ -19,9 +18,7 @@ public class Start
|
|||||||
{
|
{
|
||||||
public Start()
|
public Start()
|
||||||
{
|
{
|
||||||
//Transmitter transmitter = new Transmitter();
|
|
||||||
ChatView view = new ChatView();
|
ChatView view = new ChatView();
|
||||||
//CommandController controller_commands = new CommandController(view, transmitter);
|
|
||||||
CommandController controller_commands = new CommandController(view);
|
CommandController controller_commands = new CommandController(view);
|
||||||
controller_commands.registerEvents();
|
controller_commands.registerEvents();
|
||||||
controller_commands.registerCommands();
|
controller_commands.registerCommands();
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package ChatProgramm.controller;
|
|||||||
import ChatProgramm.controller.commands.CommandConnect;
|
import ChatProgramm.controller.commands.CommandConnect;
|
||||||
import ChatProgramm.controller.commands.CommandInvoker;
|
import ChatProgramm.controller.commands.CommandInvoker;
|
||||||
import ChatProgramm.controller.commands.CommandSend;
|
import ChatProgramm.controller.commands.CommandSend;
|
||||||
import ChatProgramm.model.Transmitter;
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@@ -21,15 +20,8 @@ import java.awt.event.ActionListener;
|
|||||||
public class CommandController implements ActionListener{
|
public class CommandController implements ActionListener{
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
//private Transmitter transmitter;
|
|
||||||
private CommandInvoker invoker;
|
private CommandInvoker invoker;
|
||||||
|
|
||||||
// public CommandController(ChatView view, Transmitter transmitter){
|
|
||||||
// this.view = view;
|
|
||||||
// this.transmitter = transmitter;
|
|
||||||
// this.invoker = new CommandInvoker();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public CommandController(ChatView view){
|
public CommandController(ChatView view){
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.invoker = new CommandInvoker();
|
this.invoker = new CommandInvoker();
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ChatProgramm.controller;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author ahren
|
|
||||||
*/
|
|
||||||
public class 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@ import ChatProgramm.model.Server;
|
|||||||
import ChatProgramm.util.OhmLogger;
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JRadioButton;
|
import javax.swing.JRadioButton;
|
||||||
@@ -25,12 +24,10 @@ public class CommandConnect implements CommandInterface
|
|||||||
private JRadioButton rBtnClient;
|
private JRadioButton rBtnClient;
|
||||||
private JDialog dialogFenster;
|
private JDialog dialogFenster;
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
|
||||||
private CommandSend commandSend;
|
private CommandSend commandSend;
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
|
||||||
public CommandConnect(ChatView view, CommandInterface value)
|
public CommandConnect(ChatView view, CommandInterface value)
|
||||||
{
|
{
|
||||||
rBtnServer = view.getBtnServer();
|
rBtnServer = view.getBtnServer();
|
||||||
rBtnClient = view.getBtnClient();
|
rBtnClient = view.getBtnClient();
|
||||||
|
|||||||
@@ -13,6 +13,5 @@ public interface CommandInterface
|
|||||||
{
|
{
|
||||||
public void execute();
|
public void execute();
|
||||||
public void undo();
|
public void undo();
|
||||||
// public void redo();
|
|
||||||
public boolean isUndoable();
|
public boolean isUndoable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,14 @@
|
|||||||
|
|
||||||
package ChatProgramm.controller.commands;
|
package ChatProgramm.controller.commands;
|
||||||
|
|
||||||
import ChatProgramm.controller.Nachricht;
|
|
||||||
import ChatProgramm.model.Client;
|
import ChatProgramm.model.Client;
|
||||||
import ChatProgramm.model.Server;
|
import ChatProgramm.model.Server;
|
||||||
import ChatProgramm.model.Transmitter;
|
|
||||||
import ChatProgramm.model.TransmitterInterface;
|
import ChatProgramm.model.TransmitterInterface;
|
||||||
import ChatProgramm.util.OhmLogger;
|
import ChatProgramm.util.OhmLogger;
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
import ChatProgramm.model.Nachricht;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -23,14 +20,16 @@ import javax.swing.JTextField;
|
|||||||
*/
|
*/
|
||||||
public class CommandSend implements CommandInterface
|
public class CommandSend implements CommandInterface
|
||||||
{
|
{
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = OhmLogger.getLogger();
|
||||||
|
private JTextField eingabeFeld;
|
||||||
|
private String nachricht;
|
||||||
|
private ChatView view;
|
||||||
|
public TransmitterInterface transmitterInterface;
|
||||||
|
public Server server;
|
||||||
|
public Client client;
|
||||||
|
|
||||||
|
|
||||||
private ChatView view;
|
|
||||||
public TransmitterInterface transmitterInterface;
|
|
||||||
private JTextField eingabeFeld;
|
|
||||||
|
|
||||||
public Server server;
|
|
||||||
public Client client;
|
|
||||||
|
|
||||||
public CommandSend(ChatView view)
|
public CommandSend(ChatView view)
|
||||||
{
|
{
|
||||||
@@ -43,11 +42,12 @@ public class CommandSend implements CommandInterface
|
|||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
if(transmitterInterface != null && !eingabeFeld.getText().isEmpty()){
|
if(transmitterInterface != null && !eingabeFeld.getText().isEmpty()){
|
||||||
transmitterInterface.send(new Nachricht(eingabeFeld.getText()));
|
transmitterInterface.send(eingabeFeld.getText());
|
||||||
eingabeFeld.setText("");
|
eingabeFeld.setText("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUndoable()
|
public boolean isUndoable()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,9 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import ChatProgramm.util.OhmLogger;
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
@@ -18,26 +16,15 @@ import java.util.logging.*;
|
|||||||
*/
|
*/
|
||||||
public class Client extends Transmitter {
|
public class Client extends Transmitter {
|
||||||
|
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = Logger.getLogger("netz");
|
||||||
|
private static final int PORT = 35000; //lt. iana port > 2¹⁵
|
||||||
|
private static final String IP = "127.0.0.1";
|
||||||
|
|
||||||
|
|
||||||
public Client(ChatView view) throws IOException {
|
public Client(ChatView view) throws IOException {
|
||||||
super(view);
|
super(view);
|
||||||
connect();
|
connect();
|
||||||
initIO();
|
initIO();
|
||||||
|
|
||||||
// out.println("Hallo Du Server - ich bin ein Client");
|
|
||||||
// out.flush();
|
|
||||||
//
|
|
||||||
// lg.info("Client: warte auf Serverantwort");
|
|
||||||
//
|
|
||||||
// String nachricht = in.readLine(); // ACHTUNG blockiert
|
|
||||||
// lg.info("Client: Serverbestätigung erhalten");
|
|
||||||
//
|
|
||||||
// lg.info("Client: fertig");
|
|
||||||
// in.close();
|
|
||||||
// out.close();
|
|
||||||
// s.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -47,11 +34,8 @@ public class Client extends Transmitter {
|
|||||||
lg.info("Client: Verbindung wird aufgebaut");
|
lg.info("Client: Verbindung wird aufgebaut");
|
||||||
socket = new Socket(IP, PORT);
|
socket = new Socket(IP, PORT);
|
||||||
lg.info("Client: Verbindung aufgebaut");
|
lg.info("Client: Verbindung aufgebaut");
|
||||||
|
|
||||||
} catch (java.io.InterruptedIOException e) {
|
} catch (java.io.InterruptedIOException e) {
|
||||||
lg.warning("Timeout" + "(" + timeout / 1000 + "s)");
|
lg.warning("Timeout" + "(" + timeout / 1000 + "s)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author ahren
|
||||||
|
*/
|
||||||
|
public class Nachricht
|
||||||
|
{
|
||||||
|
private String nachricht;
|
||||||
|
|
||||||
|
public Nachricht(String nachricht)
|
||||||
|
{
|
||||||
|
this.nachricht = nachricht;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the nachricht
|
||||||
|
*/
|
||||||
|
public String getNachricht() {
|
||||||
|
return nachricht;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNachricht(String nachricht) {
|
||||||
|
this.nachricht = nachricht;
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-3
@@ -2,7 +2,7 @@
|
|||||||
* 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.model;
|
||||||
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.util.concurrent.Flow;
|
import java.util.concurrent.Flow;
|
||||||
@@ -29,7 +29,8 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(Nachricht item) {
|
public void onNext(Nachricht item) {
|
||||||
view.getTxtChat().setText(item.getNachricht());
|
|
||||||
|
view.getTxtChat().append(item.getNachricht());
|
||||||
this.subscription.request(1);
|
this.subscription.request(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +39,6 @@ public class ReceiveAdapter implements Subscriber<Nachricht> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,73 +2,44 @@
|
|||||||
* 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.util.OhmLogger;
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
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.io.UnsupportedEncodingException;
|
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
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 = OhmLogger.getLogger();
|
private static Logger lg = Logger.getLogger("netz");
|
||||||
|
private static final int PORT = 35000; //lt. iana port > 2¹⁵
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connect() throws IOException {
|
|
||||||
try {
|
|
||||||
ServerSocket sSocket = new ServerSocket(PORT);
|
|
||||||
sSocket.setSoTimeout(timeout);
|
|
||||||
lg.info("Server: warte auf Verbindung");
|
|
||||||
socket = sSocket.accept();
|
|
||||||
lg.info("Server: Verbindung akzeptiert");
|
|
||||||
|
|
||||||
} catch (java.io.InterruptedIOException e) {
|
|
||||||
lg.warning("Timeout" + "(" + timeout / 1000 + "s)");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void connect() throws IOException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ServerSocket sSocket = new ServerSocket(PORT);
|
||||||
|
sSocket.setSoTimeout(timeout);
|
||||||
|
lg.info("Server: warte auf Verbindung");
|
||||||
|
socket = sSocket.accept();
|
||||||
|
lg.info("Server: Verbindung akzeptiert");
|
||||||
|
}
|
||||||
|
catch ( java.io.InterruptedIOException e )
|
||||||
|
{
|
||||||
|
lg.warning("Timeout"+"("+timeout/1000+"s)");
|
||||||
|
}
|
||||||
|
}
|
||||||
public Server(ChatView view) throws IOException {
|
public Server(ChatView view) throws IOException {
|
||||||
super(view);
|
super(view);
|
||||||
connect();
|
connect();
|
||||||
initIO();
|
initIO();
|
||||||
|
|
||||||
// String nachricht = in.readLine(); // ACHTUNG blockiert
|
|
||||||
// lg.info("Server: Nachricht erhalten");
|
|
||||||
// System.out.println("Server: NACHRICHT = " + nachricht);
|
|
||||||
//
|
|
||||||
// // ACHTUNG: blockiert NICHT!!!!
|
|
||||||
// out.println("Server an Client: Nachricht erhalten");
|
|
||||||
// out.flush(); // wichtig
|
|
||||||
//
|
|
||||||
// lg.info("Server: fertig");
|
|
||||||
// in.close();
|
|
||||||
// out.close();
|
|
||||||
// s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import ChatProgramm.controller.Nachricht;
|
|
||||||
import ChatProgramm.controller.ReceiveAdapter;
|
|
||||||
import ChatProgramm.util.OhmLogger;
|
|
||||||
import ChatProgramm.view.ChatView;
|
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;
|
||||||
@@ -16,6 +12,7 @@ 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.Socket;
|
import java.net.Socket;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -29,126 +26,122 @@ import java.util.logging.Logger;
|
|||||||
*
|
*
|
||||||
* @author ahren
|
* @author ahren
|
||||||
*/
|
*/
|
||||||
public abstract class Transmitter implements Runnable, Subscriber<Nachricht>, TransmitterInterface {
|
public abstract class Transmitter implements Runnable, Subscriber<String>, TransmitterInterface {
|
||||||
|
|
||||||
static final int timeout = 30000;
|
static final int timeout = 60000;
|
||||||
protected static final int PORT = 35000;
|
private static final int PORT = 35000;
|
||||||
protected static final String IP = "127.0.0.1";
|
|
||||||
|
|
||||||
private static Logger lg = OhmLogger.getLogger();
|
private static Logger lg = Logger.getLogger("netz");
|
||||||
|
|
||||||
protected Socket socket;
|
protected Socket socket;
|
||||||
protected BufferedReader reader;
|
protected BufferedReader reader;
|
||||||
protected PrintWriter writer;
|
protected PrintWriter writer;
|
||||||
|
|
||||||
|
private Nachricht nachricht;
|
||||||
|
private String txtNachricht;
|
||||||
|
private boolean laufend;
|
||||||
private SubmissionPublisher<Nachricht> textPublisher;
|
private SubmissionPublisher<Nachricht> textPublisher;
|
||||||
private ExecutorService eService;
|
private ExecutorService eService;
|
||||||
private boolean laufend = false;
|
private String receivedString;
|
||||||
|
|
||||||
private ChatView view;
|
private ChatView view;
|
||||||
|
|
||||||
private ReceiveAdapter receiveAdapter;
|
private ReceiveAdapter receiveAdapter;
|
||||||
|
|
||||||
public Transmitter(ChatView view) {
|
public Transmitter(ChatView view)
|
||||||
socket = new Socket();
|
{
|
||||||
eService = null;
|
socket = new Socket();
|
||||||
this.view = view;
|
eService = null;
|
||||||
textPublisher = new SubmissionPublisher<>();
|
receiveAdapter = new ReceiveAdapter(view);
|
||||||
|
textPublisher = new SubmissionPublisher<>();
|
||||||
|
this.view = view;
|
||||||
|
addWertSubscription(receiveAdapter);
|
||||||
|
nachricht = new Nachricht("");
|
||||||
|
}
|
||||||
|
|
||||||
receiveAdapter = new ReceiveAdapter(view);
|
public void addWertSubscription(Subscriber<Nachricht> subscriber)
|
||||||
addWertSubscription(receiveAdapter);
|
{
|
||||||
|
textPublisher.subscribe(subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
InputStream is = socket.getInputStream();
|
InputStream is = socket.getInputStream();
|
||||||
OutputStream os = socket.getOutputStream();
|
OutputStream os = socket.getOutputStream();
|
||||||
|
|
||||||
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
|
||||||
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
OutputStreamWriter osr = new OutputStreamWriter(os, "UTF-8");
|
||||||
|
|
||||||
reader = new BufferedReader(isr);
|
reader = new BufferedReader(isr);
|
||||||
writer = new PrintWriter(osr);
|
writer = new PrintWriter(osr);
|
||||||
lg.info("Initialisierung abgeschlossen");
|
lg.info("Reader / Writer Initialisierung abgeschlossen");
|
||||||
|
startempfangen();
|
||||||
|
lg.info("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(){
|
public void send(String txtNachricht){
|
||||||
synchronized (this){
|
|
||||||
laufend = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eService == null){
|
writer.println(txtNachricht);
|
||||||
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();
|
writer.flush();
|
||||||
|
lg.info("Nachricht gesendet");
|
||||||
lg.info("Nachricht wird angezeigt");
|
nachricht.setNachricht("\nDu: " + txtNachricht);
|
||||||
textPublisher.submit(nachricht);
|
textPublisher.submit(nachricht);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Nachricht receive(){
|
public Nachricht receive(){
|
||||||
Nachricht nachricht = new Nachricht("");
|
try {
|
||||||
try {
|
txtNachricht = reader.readLine();
|
||||||
String txtNachricht = reader.readLine();
|
if(!txtNachricht.isEmpty()){
|
||||||
if(!txtNachricht.isEmpty()){
|
lg.info("Nachricht erhalten");
|
||||||
lg.info("Nachricht erhalten");
|
nachricht.setNachricht("\nEr / Sie: " + txtNachricht);
|
||||||
nachricht.setNachricht(txtNachricht);
|
return nachricht;
|
||||||
return nachricht;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
return nachricht;
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return nachricht;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void disconnect (){
|
||||||
|
// in.close();
|
||||||
|
// out.close();
|
||||||
|
// s.close();
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (true) {
|
||||||
lg.info("Warte auf Nachricht");
|
lg.info("Warte auf Nachricht");
|
||||||
if(laufend) {
|
if(laufend) {
|
||||||
Nachricht eingehendeNachricht = receive();
|
nachricht = receive();
|
||||||
|
if(!nachricht.getNachricht().isEmpty()){
|
||||||
if(!eingehendeNachricht.getNachricht().isEmpty()){
|
textPublisher.submit(nachricht);
|
||||||
textPublisher.submit(eingehendeNachricht);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Flow.Subscription subscription) {
|
public void onSubscribe(Flow.Subscription subscription) {
|
||||||
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
|
||||||
@@ -159,9 +152,15 @@ public abstract class Transmitter implements Runnable, Subscriber<Nachricht>, Tr
|
|||||||
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
|
private void startempfangen()
|
||||||
public void onNext(Nachricht item) {
|
{
|
||||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
synchronized (this){
|
||||||
|
laufend = true;
|
||||||
}
|
}
|
||||||
|
if (eService == null){
|
||||||
|
eService = Executors.newSingleThreadExecutor();
|
||||||
|
eService.execute(this);
|
||||||
|
}
|
||||||
|
lg.info("Starte Chat");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||||
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
import ChatProgramm.controller.Nachricht;
|
import ChatProgramm.model.Nachricht;
|
||||||
|
/**
|
||||||
public interface TransmitterInterface{
|
*
|
||||||
public void send(Nachricht nachricht);
|
* @author ahren
|
||||||
|
*/
|
||||||
|
public interface TransmitterInterface
|
||||||
|
{
|
||||||
|
public void send(String txtNachricht);
|
||||||
public Nachricht receive();
|
public Nachricht receive();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user