To show a simple example, I want to send multiple messages to a node.js tcp socket. I only want to send the second message when the first message is fully sent/drained. Howeve
TCP does not send messages "separately". TCP is a stream protocol, which means that when you write bytes to the socket, you get the same bytes in the same order at the receiving end. There is no notion of "message boundaries" or "packets" anything of the sort.
In your example, the callback is called when the socket layer accepts your data for transmission. It does not mean that the data has been successfully sent, or even that it has left your computer at all. In your callback, you send a second message, but the socket layer combines that with the first message for efficiency because it doesn't matter to TCP.