我想通过自己的Java客户端连接到IRC,但是有一个问题
每当IRC服务器发送ping命令如PING:6E17BFF我必须返回此PONG:6E17BFF
您可以在下面看到我使用的代码。我做错了吗?
每次我连接时都会收到此
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)
我希望你能帮助我
代码
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));
}
}
答案 0 :(得分:1)
这是我在教学机器人中用来处理Ping / Pong的代码。正如您将看到的那样,我将我的测试响应留在原处,以便我验证该过程是否有效。
//******************************************************************************
//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");
}