It is extremely rare to happen but I can’t seem to figure out if it’s a Twitch anomaly or I’m doing something wrong, but, from what I can tell it appears to be sent to me this way since my code is pretty basic:
Since you are appearing to be on nodejs. Instead of using net look at either tmi.js. Or my own fork of node-irc on GitHub. Tmi.js will save you a huge chunk of implementation work
In regards to your code: You do not split the incoming data at all?
As far as I know, twitchs websocket servers always send full messages (no chunking), so a simple data.split("\r\n") should do the trick - after that, iterate over the split parts. Additionally, I suggest using a proper IRC message parser (like the npm package irc-message) instead of things like indexOf, you will be glad you did.
Barry suggested you use tmi.js or similar, for a beginner that is not a bad idea.
If Twitch isn’t chunking the messages and there’s nothing in my code doing it I guess it’s something wrong with the net module or? Either way, that’s exactly what I ended up doing the other day and it works fine:
if(data.indexOf('PRIVMSG') >= 0) {
lines = data.split('\r\n');
if (lines[lines.length-1] === '')
lines.pop();
for (var i = 0; i < lines.length; i++) {
individual line stuff...
Although I’m not a beginner, sometimes I do code like one lol. I don’t mind writing stuff myself (as a challenge/for learning purposes) I just don’t remember having this issue with the base TWITCHCLIENT or without CAP REQ tags.
Twitch batches messages that get sent (nearly) at the same time, which is why you have to split them manually. There is nothing wrong with the net module
If that code works fine, all is well.
EDIT: I dont know exactly how net handles this, but there is a chance that long messages will arrive in parts (chunks, usually 512 bytes or something). In this case, you will have to keep a buffer of received data and split off only complete lines including \r\n. This is default handling, and if you look into the popular IRC packages, all do that.
My own code looks like this: https://gist.github.com/CBenni/4538837f6c0d5b272985