Will not stay connected (IRC)

Alright, so I have been having this problem for a while, and I need some help. I use this command to try and send a PONG to the Irc Server, but it doesn’t want to work.

        while((line = reader.readLine()) != null){
    	if(line.toLowerCase().startsWith("PING ")){
    		writer.write("PONG " + line.substring(5) + "\r\n");
    		writer.flush();
    	}else{
    		System.out.println(line);
    	}
    }

Any help would be greatly appreciated.

What exactly do you mean when you say it doesn’t want to work? What is the output of that code when you run it?

Well, I can’t exactly say what is says, but when I get the ping from tmi.twitch.tv then I get kicked because my bot doesn’t want to respond.

I’d recommend using a debugger or putting in System.out.println() for your variables so that you can see exactly where your bot stops responding.

Alright, I’ll do that when I can connect to Twitch IRC again.

You’d be better off asking this in a JAVA forum, but I can tell you where this goes wrong:

line.toLowerCase().startsWith("PING ")

You’re comparing a lower case String to an upper case one.

Also, to make it easier on yourself, you can instead of writing and then flushing to the socket, use the println() method on a PrintWriter to write to the output stream (this will then send a new line without all the extra code)