I am currently developing a chat application which is quite basic overall, however I am encountering problems when receiving strings from both the client and the server side. I am using a thread to passively listen on the socket for incoming messages, which is where I suspect the problem to be. Am I doing this the right way?
Source: Code for sending strings:
send.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
messageBuffer = message.getText();
out.println(messageBuffer);
chat.append(username + ": " + messageBuffer + "\n");
message.setText("");
}
});
I then have this which passively listens (problem is probably here):
public void run(){
while(true){
try {
messageBufferIn = in.readLine();
System.out.println(in.readLine());
chat.append(recipient + ": " + messageBufferIn + "\n");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Im also calling the thread using this:
public static void startChatting(){
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
Thanks for any help you can provide, Im still new to threads overall so my mistake might be quite mediocre.
Edit: The problem is when I try sending a message to the receiver, nothing comes through, I can confirm that they are connected. In fact the System.out.println(in.readLine()); doesnt come through at all, not even a "null" output.