I have two node processes that speak to each other. I will call them [Node Server] and [Node Sender]. [Node Sender] continually processes information and writes a message over a TCP connection to [Node Server]. [Node Server] then writes back a status message.
Example of [Node Sender]:
var message = "Test Message";
[Node Sender].connection.write(message);
Example of [Node Server]:
[Node Server].socket.on("data", function(p_data) {
this.write("OK");
// Do some work with p_data
}
This works without issue, p_data always contains "Test Message" when sent at anything above 5 milliseconds. However, if I speed [Node Sender] to write every millisecond, p_data occasionally ends up with something like "Test MessageTest MessageTes".
I understand that the buffer in [Node Sender] is probably filling faster than the write command is sending it. Is there a way to force a one-to-one ratio in sending messages while still remaining asynchronous?
I can certainly just add a terminator to my message and just fill a buffer in [Node Server], but I wanted to make sure there wasn't something obvious I was missing.