Reputation: 1
I wanna connect to IRC through my own Java client, but there is a problem
Whenever IRC server sends me ping request like PING :6E17BFF I must return this PONG :6E17BFF
You can see the code I'm using below. Have I'm doing something wrong?
Each time when I'm connecting I receive this
NOTICE AUTH :*** Looking up your hostname...
NOTICE AUTH :*** Couldn't resolve your hostname; using your IP address instead
PING :6E17BFF
PONG :6E17BFF
ERROR :Closing Link: TestNick[ipaddress] (Ping timeout: 33 seconds)
I hope you can help me
Code
while ((line = reader.readLine( )) != null) {
System.out.println(line);
if(line.substring(0,4).equals("PING")){
writer.write("PONG :"+line.substring(6)+"\n\r");
System.out.println("PONG :"+line.substring(6));
}
}
Upvotes: 0
Views: 613
Reputation: 11
This is the code I use to handle Ping / Pong in a teaching bot. As you will see I left my test responses in place that I used to verify that the process was working.
//******************************************************************************
//PING PONG Handler and while loop test. Tests to be removed before full implementation
//******************************************************************************
while((line = in.readLine()) != null) {
System.out.println("<--" + line);
if (line.startsWith("PING")) {
//sendPrivmsg("#Test", "The server just PINGED!");
//sendPrivmsg("#Test", "Yes, and it was answered with a PONG!");
writeLine(line.replace("PING", "PONG"));
//sendPrivmsg("#Test", "This is a private message to channel #Test Pong Pong Pong Pong Pong");
}
Upvotes: 1