I’m using Python to grab chat messages. Eventually, after some time, the IRC seems to start returning empty strings and doesn’t revert to sending actual messages. When I restart my program, it’ll go back to working without issue for some time, until it inevitable happens again.
Is this what happens when a program sends too many requests to the IRC server? I’m thinking no, since it starts working again as soon as I restart the program, but I can’t think of what else it could be, due to it working initially, but then inevitably breaking.
The problem with the disconnect logic in that code is that there is none. When you do a blocking receive like that, getting no data back from the recv() call means that the connection has been dropped by the other end. The official documentation for Python’s socket library doesn’t seem to mention it, but the info is out there.
Also, with TCP, there’s no guarantee that what you get from a given receive call is going to contain neatly grouped protocol messages, especially when you start getting a lot of them coming in. What I generally do is append the raw data coming in to a working buffer (not really a Python developer, so I don’t know how you’d do that), search that buffer for the message delimiter (\n in this case), and separate the messages myself. If I have data left over but can’t find a message delimiter in it, I keep that in its raw state and wait for more to come in.