I made a ReadMessage thread that should run in the background and read messages when they come in. This is how it looks:
Thread ReadMessages = new Thread(new Runnable() {
public void run() {
try {
while(socket.isConnected()){
ServerMsg = in.readLine();
jTextArea1.append(ServerMsg);
}
} catch (IOException ex) {
System.out.println("Something went wrong! THREAD");
}
}
});
I start it everytime i start my program:
public TwitchBotFenster() throws IOException, Exception {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
initComponents();
ReadMessages.start();
}
The problem I have, is that it only reads the first messages when I connect to twitch irc but if I write something in the chat it doesnt. I dont really get the problem. My thoughts when I made that were, whenever the socket is connected it should read all the messages.
EDIT:
This is how i send messages to the server:
public void SendMessage() throws IOException{
try{
if(BotName == null){
this.jTextArea1.append("You are not logged in!\n");
}else{
this.ClientChatMessage = this.jTextField4.getText();
out.write(":" + BotName + "!" + BotName + "@" + BotName + ".tmi.twitch.tv PRIVMSG #" + this.Channelname + " :" + this.ClientChatMessage + "\n");
out.flush();
this.jTextField4.setText("");
this.jTextArea1.append("*" + BotName + ">> " + ClientChatMessage + "\n");
}
this.jTextField4.setText("");
}catch(Exception exe){
System.out.println("Something went horribly wrong! (SendMessage/func)\n");
}
}
EDIT2:
Messages are sent whenever i press enter in my jTextField:
private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {
try {
SendMessage();
} catch (IOException ex) {
System.out.println("Something went horribly wrong! (SendMessage)\n");
}
}