fixed multiple writes at the same time on a socket (still not perfect,
to be continued)