IRC disconnects after 1 minute of inactivity

I’m making a Python bot, and I have noticed that after a few minutes of running, my bot disconnects from the server and doesn’t receive anymore messages. At first I thought that I’m not receiving PING messages, but after many tests I figured out that after 1 minute of no messages received from the server the socket just stops working. I can solve this by simply sending PRIVMSG to the bot’s channel if nothing happened for 1 minute, but I suppose it shouldn’t be like that.
Any ideas for what might be causing it?

If you don’t send a PONG back to the server when receiving a PING the server will kick you after 1-3 minutes for being idle.

The thing is, I disconnect from the server before I even receive a ping and always after 1 minute of inactivity. I only receive the PING message after about 5 minutes.

I have observed something like this.

The nodeJS irc library, uses a cycling ping timer, if it’s not seen a ping for a while it sends it’s own.

I antitcpate the connection is being closed by your Python code, becuase it thinks the server is dead, rather than sending it’s own PING

Thanks for the answer, is there a way of keeping the socket alive other than sending PRIVMSG every minute?

  • Change the Library you are using, to have a longer timeout

  • Send a PING yourself every minute

I’m using the socket library, also what do you mean by PING yourself?
Sorry in advance if it is a noob question…

In IRC connections the Server sends a PING command to the client and if everything is right the client should send a PONG command to the server. This is how IRC determines if a client is still connected to the server.

From RFC 2812

The PING command is used to test the presence of an active client or
server at the other end of the connection. Servers send a PING
message at regular intervals if no other activity detected coming
from a connection. If a connection fails to respond to a PING
message within a set amount of time, that connection is closed. A
PING message MAY be sent even if the connection is active.

What I think @BarryCarlyon is trying to say is that you can send a PING [edited] without previously receiving a PING from the server. The PING would still reach the server, the server would respond with a PONG and “refresh” your connection time.

You can send a PING to the server and have it respond with a PONG.

Oh, I didn’t knew that. I thought we would have to send the PONG since we are the client but now that I think about it, it’s kinda stupid :sweat_smile: Well, my message still stands though, just send a PING instead of a PONG.

I tried doing so and it does keep the connection alive, but whenever I send a privmsg after I sent that ping it bugs and doesn’t work…

Make sure you’re including the \r\n at the end of the Ping message.

Thanks, it works now.

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