Browse Source

Merge origin/master

Conflicts:
	src/wuerfelthreads/Start.java
	src/wuerfelthreads/view/WuerfelView.form
	src/wuerfelthreads/view/WuerfelView.java
no_lib
BakeOrDie 3 years ago
parent
commit
f4ca6302e7

+ 0
- 1
src/graphicChat/Start.java View File

ReceiveAdapter recAdapter = new ReceiveAdapter(view, model); ReceiveAdapter recAdapter = new ReceiveAdapter(view, model);
recAdapter.subscribe(); recAdapter.subscribe();
view.setVisible(true);
view.setTitle("Chat"); view.setTitle("Chat");


view.setSize(800, 600); view.setSize(800, 600);

+ 1
- 1
src/graphicChat/controller/CommandSend.java View File

import graphicChat.model.Figure; import graphicChat.model.Figure;
import graphicChat.view.ChatView; import graphicChat.view.ChatView;
import java.util.List; import java.util.List;
import java.util.function.Supplier;






if(src == view.getBtnSend()){ if(src == view.getBtnSend()){
/* view get figures*/ /* view get figures*/
msg = model.getFigures(); msg = model.getFigures();

model.sendMessage(msg); model.sendMessage(msg);
view.getLblStatus().setText("Nachricht gesendet"); view.getLblStatus().setText("Nachricht gesendet");
} }

+ 31
- 24
src/graphicChat/model/ChatModel.java View File

import java.util.logging.Logger; import java.util.logging.Logger;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List; import java.util.List;


/** /**
List<Figure> msg; List<Figure> msg;
BufferedReader in;
PrintWriter out;
ObjectInputStream objectisr;
// BufferedReader in;
// PrintWriter out;
ObjectOutputStream objectOutput;
ObjectInputStream objectInput;
private Socket socket; private Socket socket;


try { try {
try try
{ {
msg = (List<Figure>)objectisr.readObject();
lg.info("test");
msg = (List<Figure>)objectInput.readObject();
} }
catch (ClassNotFoundException ex) catch (ClassNotFoundException ex)
{ {
} }
} }


public void setSocket(Socket s) throws IOException {
lg.info("start communication\n");
public void setSocket(Socket s) throws IOException
{
InputStream iStream = s.getInputStream(); InputStream iStream = s.getInputStream();
OutputStream oStream = s.getOutputStream(); OutputStream oStream = s.getOutputStream();
ObjectInputStream oisr = new ObjectInputStream(iStream);
InputStreamReader isr = new InputStreamReader(iStream, "UTF-8");
OutputStreamWriter osr = new OutputStreamWriter(oStream, "UTF-8");
objectOutput = new ObjectOutputStream(oStream);
// objectOutput.writeObject(msg);



// BufferedWriter out = new BufferedWriter(osr);
objectisr = oisr;
out = new PrintWriter(osr);
in = new BufferedReader(isr);
objectInput = new ObjectInputStream(iStream);
start(); start();
} }

public void setClient(int PORT, String IP_ADRESSE) throws IOException public void setClient(int PORT, String IP_ADRESSE) throws IOException
{ {
Thread connectThread;
connectThread = new Thread(new Runnable() {
Thread connectThread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
lg.info("Client: verbinde ..."); lg.info("Client: verbinde ...");
Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert! Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert!
lg.info("Client: Verbindung hergestellt");
setSocket(s); setSocket(s);
} catch (IOException e) {
lg.info("io exception in setClient");
lg.info("Client: Verbindung hergestellt");
} catch (Exception e) {
// e.printStackTrace();
lg.info("Client: Verbindung fehlgeschlagen: " + e);
} }
} }
}); });
ServerSocket sSocket = new ServerSocket(PORT); ServerSocket sSocket = new ServerSocket(PORT);
lg.info("Server: Warte auf Verbindung ..."); lg.info("Server: Warte auf Verbindung ...");
Socket s = sSocket.accept(); // Achtung: blockiert! Socket s = sSocket.accept(); // Achtung: blockiert!
lg.info("Server: Verbindung akzeptiert");
setSocket(s); setSocket(s);
lg.info("Server: Verbindung akzeptiert");
} catch (IOException e) { } catch (IOException e) {
lg.info("io exception in setServer");
// e.printStackTrace();
lg.info("Server: Verbindung fehlgeschlagen: " + e);
} }
} }
}); });
{ {
if(laufend){ if(laufend){
lg.log(Level.INFO, "Sende Nachricht: "); lg.log(Level.INFO, "Sende Nachricht: ");
out.println(msg);
out.flush();
try
{
objectOutput.writeObject(msg);
//objectOutput.flush();
}
catch (IOException ex)
{
Logger.getLogger(ChatModel.class.getName()).log(Level.SEVERE, null, ex);
}
} }
else{ else{
lg.log(Level.INFO, "Keine Verbindung!"); lg.log(Level.INFO, "Keine Verbindung!");

Loading…
Cancel
Save