|
|
|
|
|
|
|
|
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!"); |