Websocket connection times out after 10-15 minutes despite replying to PINGs

I’m trying to have a python script connect to twitch chat through a websocket and interact with users from what messages they send. Y’know, basic bot stuff.

Everything works perfectly fine for the first ten minutes or so. I connect to the IRC, I’m receiving messages properly, and everything is going smoothly. However, after about 10-15 minutes, I just start getting thousands of blank messages from the websocket every second. I thought this was because I wasn’t replying to the PING messages I was getting, but every variation of reply to the PINGs I could think of didn’t work, and I still get flooded with empty messages.

Replies that I’ve tried:
bytes(‘PONG’,“UTF-8”)
bytes(‘PING’, “UTF-8”)
bytes(“PONG irc.chat.twitch.tv”,“UTF-8”)
bytes(“PING irc.chat.twitch.tv”, “UTF-8”)
bytes(“PONG tmi.twitch.tv”,“UTF-8”)
bytes(“PING tmi.twitch.tv”,“UTF-8”)

I’ve also tried waiting for an empty message and then reconnecting, but that throws an error as well, saying “A request to send or recieve data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied” [WinError 10057]. I have no idea why this error is coming up, because I am supplying the websocket with the IP and Port of the IRC.

I’m at a total loss as to what to do now. I’ve tried everything I can think of to get this working and I can’t find anything else even remotely close to this issue out there on the internet save for a single post on this forum from ~2 years ago that doesn’t include a solution.

This example might help

It’s in nodeJS, but however demonstrates a userthing thing:

If I don’t get a Twitch sent PING in a defined time, I send my own PING for Twitch to PONG to.

This might help keep your connection alive.

Don’t know if your problem is a server connectivity issue or actually a problem with your code.

I tried adding something similar where my code will wait roughly 3 minutes for a ping, and then send it’s own, but I still get the same result. I’ve been having this issue for over a week now, so if it’s a server issue I’d be kinda surprised.

Might be a routing issue between you and Twitch. I don’t have this issue myself (from Canada, France or London)

Is there even anything I can do to try and fix that? Or am I stuck here with a finger up my own praying that, at some point, it fixes itself?

Try your code on another server?
Ask your server provider about routing issues (some might not even allow IRC type stuff running and thats the issue you are having it’s getting shutdown by the provider)?
If you use digital ocean, they seem to have routing issues quite often

All of this is being run off a desktop PC, and will eventually be ran off a raspberry pi. The only thing between me and twitch that might be interfering is PiHole, but I checked the Query and nothing is being blocked pertaining to this application. So I can say with a good degree of certainty that IRC is being allowed.

Then it might be an issue with your ISP or something else.

Not sure what else I can suggest when all my things look ok to me.

You seem to be doing everything correct, so that leaves routing.

I use AT&T for my ISP, you think it might be because of the issues they’ve been experiencing since that whole christmas fiasco in Tenessee? Some of my other stuff was affected like my cell service.

(Not that I expect you to know everything about their routing, just curious if it’s likely enough to warrant a phonecall)

Probably.

Worth testing your code on another server to see if your code is good vai another route.

Alright, I’ll see what happens. I appreciate your help.

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