Api/IRC ping / pong question

Hey ho,
i am working on a twitch chat statistics bot (in java), and got a small problem with the connection.
how should the response pong look like? and to which server should it send to?
atm i am opening a Socket connection to irc.twitch.tv.

socket = new Socket(irc.twitch.tv, 6667);

Joining the chat and everything works fine, i just get time out after i received the second PING.
atm my response pong looks like this:

sender.write("PONG tmi.twitch.tv");

sender is a BufferedWriter with a OutputstreamWriter bound to the socket:

sender = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

Anyone knows how i fix this?
€: i got my informations from here: https://github.com/justintv/Twitch-API/blob/master/IRC.md

kind regards


Did you flush the BufferedWriter? You also need to append \r\n to signal end of message.

sender.write("PONG tmi.twitch.tv\r\n");

Also, this should only be in the event of a PING messages. You need to listen to the socket in a BufferedReader and respond with an appropriate pong message (the same trailing characters as you received). I believe you need to be sending “PONG :tmi.twitch.tv”, but this should be generated from the message received, as in the linked example.

Take notice that the line:

if (line.toLowerCase( ).startsWith("PING ")) {

Needs to be substituted with

if (line.startsWith("PING ")) {


sender.write(“PONG tmi.twitch.tv\r\n”);

this fixed the issue.
thank you!
kind regards

1 Like

Dynamically generating the response would also allow you to gather chat statistics from big events not hosted on tmi.twitch.tv. I suggest avoiding literals with something like:

"PONG " + theServerAddress + "\r\n"


"PONG " + thePingMessage.substring(5) + "\r\n"

This is a good reference for IRC protocols: https://tools.ietf.org/html/rfc2812#section-3.7.3

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.