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

@@ -43,7 +43,6 @@ public class Start
ReceiveAdapter recAdapter = new ReceiveAdapter(view, model);
recAdapter.subscribe();
view.setVisible(true);
view.setTitle("Chat");

view.setSize(800, 600);

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

@@ -14,6 +14,7 @@ import graphicChat.model.ChatModel;
import graphicChat.model.Figure;
import graphicChat.view.ChatView;
import java.util.List;
import java.util.function.Supplier;



@@ -47,7 +48,6 @@ public class CommandSend implements ActionListener
if(src == view.getBtnSend()){
/* view get figures*/
msg = model.getFigures();

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

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

@@ -26,6 +26,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;

/**
@@ -43,9 +44,11 @@ public class ChatModel implements Runnable
List<Figure> msg;
BufferedReader in;
PrintWriter out;
ObjectInputStream objectisr;
// BufferedReader in;
// PrintWriter out;
ObjectOutputStream objectOutput;
ObjectInputStream objectInput;
private Socket socket;

@@ -77,7 +80,8 @@ public class ChatModel implements Runnable
try {
try
{
msg = (List<Figure>)objectisr.readObject();
lg.info("test");
msg = (List<Figure>)objectInput.readObject();
}
catch (ClassNotFoundException ex)
{
@@ -92,36 +96,31 @@ public class ChatModel implements Runnable
}
}

public void setSocket(Socket s) throws IOException {
lg.info("start communication\n");
public void setSocket(Socket s) throws IOException
{
InputStream iStream = s.getInputStream();
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();
}

public void setClient(int PORT, String IP_ADRESSE) throws IOException
{
Thread connectThread;
connectThread = new Thread(new Runnable() {
Thread connectThread = new Thread(new Runnable() {
@Override
public void run() {
try {
lg.info("Client: verbinde ...");
Socket s = new Socket(IP_ADRESSE, PORT); // Achtung: blockiert!
lg.info("Client: Verbindung hergestellt");
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);
}
}
});
@@ -138,10 +137,11 @@ public class ChatModel implements Runnable
ServerSocket sSocket = new ServerSocket(PORT);
lg.info("Server: Warte auf Verbindung ...");
Socket s = sSocket.accept(); // Achtung: blockiert!
lg.info("Server: Verbindung akzeptiert");
setSocket(s);
lg.info("Server: Verbindung akzeptiert");
} catch (IOException e) {
lg.info("io exception in setServer");
// e.printStackTrace();
lg.info("Server: Verbindung fehlgeschlagen: " + e);
}
}
});
@@ -152,8 +152,15 @@ public class ChatModel implements Runnable
{
if(laufend){
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{
lg.log(Level.INFO, "Keine Verbindung!");

Loading…
Cancel
Save