I am making a Java Socket Swing Application. I created this void:
private static void sendMessage(JTextField message) {
try {
String data = user + ": " + message.getText();
out.println(data);
System.out.println(in.readLine());
}
catch(Exception exc) {
JOptionPane.showMessageDialog(dpanel,
"Could not send message. Reason: " + exc, "",
JOptionPane.ERROR_MESSAGE);
}
}
The program gets jammed up after I try to send the second message to the server. Can someone provide any recommendations for my code? Thanks!
P.S.
sendMessage()
is triggered by a MouseLisitener
for a JButton
.
There is a PipeStream
for System.err
and out to a JTextArea
.
This is what in out and connection is/are:
try {
connection = new Socket(ipa, port);
out = new PrintWriter(connection.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(connection.getInputStream())));
}
...