|
@ -9,6 +9,7 @@ public class ChatClient extends JFrame implements KeyListener { |
|
|
private String address; |
|
|
private String address; |
|
|
private int port; |
|
|
private int port; |
|
|
private Socket connectionToServer; |
|
|
private Socket connectionToServer; |
|
|
|
|
|
private BufferedReader fromServerReader; |
|
|
private PrintWriter toServerWriter; |
|
|
private PrintWriter toServerWriter; |
|
|
|
|
|
|
|
|
// GUI |
|
|
// GUI |
|
@ -44,8 +45,15 @@ public class ChatClient extends JFrame implements KeyListener { |
|
|
private void receiveMessages() { |
|
|
private void receiveMessages() { |
|
|
try { |
|
|
try { |
|
|
connectionToServer = new Socket(address, port); |
|
|
connectionToServer = new Socket(address, port); |
|
|
|
|
|
fromServerReader = new BufferedReader(new InputStreamReader(connectionToServer.getInputStream())); |
|
|
toServerWriter = new PrintWriter(new OutputStreamWriter(connectionToServer.getOutputStream())); |
|
|
toServerWriter = new PrintWriter(new OutputStreamWriter(connectionToServer.getOutputStream())); |
|
|
|
|
|
|
|
|
initGui(); |
|
|
initGui(); |
|
|
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
String message = fromServerReader.readLine(); |
|
|
|
|
|
outputTextArea.append(message + "\n"); |
|
|
|
|
|
} |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); |
|
|
JOptionPane.showMessageDialog(null, "Verbindung zum Server \"" + address + "\" fehlgeschlagen."); |
|
|
} |
|
|
} |
|
|