Search code examples
javabotsirc

Java irc bot ping pong


if (serverResponse.contains("PING ")) {
    writer.write("PONG " + serverResponse.substring(5) + "\r\n");
    writer.write("PRIVMSG " + c.getHomechannel() + " :I got pinged!\r\n");
    System.out.println("pinged");
    writer.flush( );
}

and

if (cmd.equalsIgnoreCase("PING")) {
    TCPRequestManager.sendWrite("PONG " + param);
    TCPRequestManager.doMsg("c.getHomechannel()", ":I got pinged!");
    TCPConnectionManager.getWriter().flush( );
}

both SEEM to work and send me the message saying the clients been pinged but i don't think its actually returning the pong due to disconnecting, am i doing something wrong?


Solution

  • Shouldn't the PONG message contain a destination? I'm guessing the serverResponse.substring(5) in the first code block is the servername of the server pinging your server. It's expecting a PONG from your server to the irc server.

    Typically, the transaction looks something like this, a.com is the hostname of the irc server, b.com is the hostname of the bot connected to it:

    PING :a.com          (sent from a.com to b.com)
    PONG b.com :a.com    (sent from b.com to a.com)
    

    It looks like what you're sending (given the previous example) is:

    PING :a.com          (sent from a.com to b.com)
    PONG :a.com          (sent from b.com to a.com, except there's no origin)