我想通过我自己的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));
}
}发布于 2016-05-14 05:45:29
这是我用来在教学机器人中处理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");
}https://stackoverflow.com/questions/24576169
复制相似问题