Zwischenstand
This commit is contained in:
parent
7cd668f8ce
commit
109123a241
@ -42,7 +42,7 @@ public class CommandController implements ActionListener{
|
|||||||
|
|
||||||
public void registerCommands(){
|
public void registerCommands(){
|
||||||
invoker.addCommand(view.getBtnConnect(), new CommandConnect(view));
|
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
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.controller;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ahren
|
* @author ahren
|
||||||
*/
|
*/
|
||||||
class Nachricht
|
public class Nachricht
|
||||||
{
|
{
|
||||||
private String nachricht;
|
private String nachricht;
|
||||||
//private int id;
|
//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/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.model;
|
package ChatProgramm.controller;
|
||||||
|
|
||||||
import ChatProgramm.view.ChatView;
|
import ChatProgramm.view.ChatView;
|
||||||
import java.util.concurrent.Flow;
|
import java.util.concurrent.Flow;
|
@ -5,20 +5,40 @@
|
|||||||
|
|
||||||
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.util.OhmLogger;
|
||||||
|
import ChatProgramm.view.ChatView;
|
||||||
|
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;
|
||||||
|
private JTextField eingabeFeld;
|
||||||
|
|
||||||
|
public Server server;
|
||||||
|
public Client client;
|
||||||
|
|
||||||
|
public CommandSend(ChatView view)
|
||||||
|
{
|
||||||
|
this.view = view;
|
||||||
|
this.eingabeFeld = view.getTfNachricht();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
|
//Transmitter.send(new Nachricht(eingabeFeld.getText()));
|
||||||
|
lg.info("Sende Nachricht");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
import ChatProgramm.controller.Nachricht;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -25,12 +26,6 @@ public class Client extends Transmitter {
|
|||||||
|
|
||||||
private static Logger lg = Logger.getLogger("netz");
|
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 {
|
public Client() throws IOException {
|
||||||
connect();
|
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");
|
private static Logger lg = Logger.getLogger("netz");
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public void connect() throws IOException {
|
public void connect() throws IOException {
|
||||||
try {
|
try {
|
||||||
ServerSocket sSocket = new ServerSocket(PORT);
|
ServerSocket sSocket = new ServerSocket(PORT);
|
||||||
@ -47,6 +48,7 @@ public class Server extends Transmitter {
|
|||||||
|
|
||||||
|
|
||||||
public Server() throws IOException {
|
public Server() throws IOException {
|
||||||
|
super();
|
||||||
connect();
|
connect();
|
||||||
initIO();
|
initIO();
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package ChatProgramm.model;
|
package ChatProgramm.model;
|
||||||
|
|
||||||
|
import ChatProgramm.controller.Nachricht;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -26,7 +27,7 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {
|
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 int PORT = 35000;
|
||||||
protected static final String IP = "127.0.0.1";
|
protected static final String IP = "127.0.0.1";
|
||||||
|
|
||||||
@ -37,13 +38,19 @@ public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {
|
|||||||
protected PrintWriter writer;
|
protected PrintWriter writer;
|
||||||
|
|
||||||
private SubmissionPublisher<Nachricht> textPublisher;
|
private SubmissionPublisher<Nachricht> textPublisher;
|
||||||
|
private Thread thd;
|
||||||
|
private boolean laufend;
|
||||||
|
|
||||||
public Transmitter() {
|
public Transmitter() {
|
||||||
|
socket = new Socket();
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
@ -66,12 +73,36 @@ public abstract class Transmitter implements Runnable, Subscriber<Nachricht> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWertSubscription(Subscriber<Nachricht> subscriber) {
|
public void send(Nachricht nachricht) {
|
||||||
textPublisher.subscribe(subscriber);
|
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
|
@Override
|
||||||
public void run() {
|
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
|
@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
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user