Zwischenstand
This commit is contained in:
parent
7cd668f8ce
commit
109123a241
@ -42,7 +42,7 @@ public class CommandController implements ActionListener{
|
||||
|
||||
public void registerCommands(){
|
||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view));
|
||||
invoker.addCommand(view.getTfNachricht(), new CommandSend());
|
||||
invoker.addCommand(view.getTfNachricht(), new CommandSend(view));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,13 +3,13 @@
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
|
||||
package ChatProgramm.model;
|
||||
package ChatProgramm.controller;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
class Nachricht
|
||||
public class Nachricht
|
||||
{
|
||||
private String nachricht;
|
||||
//private int id;
|
@ -2,7 +2,7 @@
|
||||
* 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;
|
||||
package ChatProgramm.controller;
|
||||
|
||||
import ChatProgramm.view.ChatView;
|
||||
import java.util.concurrent.Flow;
|
@ -5,20 +5,40 @@
|
||||
|
||||
package ChatProgramm.controller.commands;
|
||||
|
||||
import ChatProgramm.controller.Nachricht;
|
||||
import ChatProgramm.model.Client;
|
||||
import ChatProgramm.model.Server;
|
||||
import ChatProgramm.model.Transmitter;
|
||||
import ChatProgramm.util.OhmLogger;
|
||||
import ChatProgramm.view.ChatView;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ahren
|
||||
*/
|
||||
public class CommandSend implements CommandInterface
|
||||
{
|
||||
public CommandSend()
|
||||
{
|
||||
private static Logger lg = OhmLogger.getLogger();
|
||||
|
||||
private ChatView view;
|
||||
private JTextField eingabeFeld;
|
||||
|
||||
public Server server;
|
||||
public Client client;
|
||||
|
||||
public CommandSend(ChatView view)
|
||||
{
|
||||
this.view = view;
|
||||
this.eingabeFeld = view.getTfNachricht();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute()
|
||||
{
|
||||
//Transmitter.send(new Nachricht(eingabeFeld.getText()));
|
||||
lg.info("Sende Nachricht");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.controller.Nachricht;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -25,12 +26,6 @@ public class Client extends Transmitter {
|
||||
|
||||
private static Logger lg = Logger.getLogger("netz");
|
||||
|
||||
private Socket socket;
|
||||
private BufferedReader reader;
|
||||
private PrintWriter writer;
|
||||
|
||||
private static final int PORT = 35000; //lt. iana port > 2¹⁵
|
||||
private static final String IP = "127.0.0.1";
|
||||
|
||||
public Client() throws IOException {
|
||||
connect();
|
||||
@ -74,9 +69,4 @@ public class Client extends Transmitter {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onNext(Nachricht item) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public class Server extends Transmitter {
|
||||
private static Logger lg = Logger.getLogger("netz");
|
||||
|
||||
|
||||
@Override
|
||||
public void connect() throws IOException {
|
||||
try {
|
||||
ServerSocket sSocket = new ServerSocket(PORT);
|
||||
@ -47,6 +48,7 @@ public class Server extends Transmitter {
|
||||
|
||||
|
||||
public Server() throws IOException {
|
||||
super();
|
||||
connect();
|
||||
initIO();
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
package ChatProgramm.model;
|
||||
|
||||
import ChatProgramm.controller.Nachricht;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -26,7 +27,7 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {
|
||||
|
||||
static final int timeout = 60000;
|
||||
static final int timeout = 10000;
|
||||
protected static final int PORT = 35000;
|
||||
protected static final String IP = "127.0.0.1";
|
||||
|
||||
@ -37,13 +38,19 @@ public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {
|
||||
protected PrintWriter writer;
|
||||
|
||||
private SubmissionPublisher<Nachricht> textPublisher;
|
||||
private Thread thd;
|
||||
private boolean laufend;
|
||||
|
||||
public Transmitter() {
|
||||
|
||||
socket = new Socket();
|
||||
}
|
||||
|
||||
public abstract void connect() throws IOException;
|
||||
|
||||
public void addWertSubscription(Subscriber<Nachricht> subscriber) {
|
||||
textPublisher.subscribe(subscriber);
|
||||
}
|
||||
|
||||
public void initIO() {
|
||||
try {
|
||||
lg.info("Initialisiere reader und writer");
|
||||
@ -66,12 +73,36 @@ public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {
|
||||
}
|
||||
}
|
||||
|
||||
public void addWertSubscription(Subscriber<Nachricht> subscriber) {
|
||||
textPublisher.subscribe(subscriber);
|
||||
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 void startServer() {
|
||||
// laufend = true;
|
||||
// if (thd == null) {
|
||||
// thd = new Thread(this);
|
||||
// thd.start();
|
||||
// }
|
||||
//
|
||||
// synchronized (thd) {
|
||||
// thd.notify();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Nachricht nachricht = new Nachricht(reader.readLine());
|
||||
textPublisher.submit(nachricht);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Transmitter.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,7 +110,6 @@ public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
||||
|
Loading…
x
Reference in New Issue
Block a user