This is your problem, check the help file, this will read one line at a time, that's why it's so slow. You can use /sockread $sock($sockname).rq &mybinvar to read the full buffer available at the time.
Thanks a lot, that fixes it! I tried that in one of my several attempts but i must have left "-fn" parameters set before [numbytes] and that made it still read line-by-line.
Btw i'm still curious about the strange behavior occurring when reading line-by-line, which makes the writing randomly stop at a random point. I also tried to measure if it stopped after a specific amount of time (maybe there was some sort of timeout) but i've seen it stop after quite different timings.