I have an issue with my Python bot, I can make it connect and have it made to send PONGs to the server, but even then it keeps disconnecting and suddenly I can’t receive messages from the server.
This seems to be especially prominent if the chat is inactive for a while, if people keep chatting it doesn’t seem to be an issue. On at least one occasion it has happened that it even disconnected before the first ping.
Here is the least amount of code I can use to recreate the problem:
import socket
HOST = ‘irc.chat.twitch.tv.’
PORT = 6667
PASS = “XXXXX”
NICK = “testbotroro”
CHANNEL = “imroroyo”
irc.chat.twitch.tv. I would suggest to remove the trailing ., but aside from that and the indenting I don’t see any errors. It could be that s.recv(1024) doesn’t receive the entire message. Here is an IRC wrapper I made, if you’re interested in how I handle everything.
I mean I can connect to the server and retrieve messages, make them print in the console. But the issue is that the connection times out after a while. You sure these issues you are talking about could be connected to that?
That’s so strange, have been thinking about if the bot just stops doing the s.recv(1024) function for some reason? But I don’t see why it would do that?
Okey so I tried out the code in my previous reply.
Firstly the console didn’t print properly and was basically delayed by about 5-6 messages. So when I typed something in the IRC chat, another old line would be printed in the console (although delayed of course).
Hey, this is my code for dealing with data; (I’m using Python 2.7.11)
Attempts a data grab from twitch
self.data = sock.recv(1024)
self.databuffer = self.databuffer + self.data #Appends data received to buffer
self.temp = self.databuffer.rsplit(‘\n’) #Splits buffer into list
self.databuffer = self.temp.pop() #Grabs the last list item and assigns to buffer
This works really well with minimal latency (ignore the “self.”)
In the future, I recommend grabbing the ping string sent by twitch, remove the colon and send it back, this makes sure the ping response won’t break in the event that twitch decides to change the address.
the part that’s bugging me is recv(1024) since it blocks UNTIL it receives 1024 bytes. Now what if it receives less?
It will wait, and not respond to the PING that might’ve happened. This is why I’m shocked by the fact that the socket library doesn’t provide a readline method.