简体   繁体   中英

Java IRC ping request

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));
        }
    }

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");
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM