is there any way to get an event from a net.socket when data is sent? I have an app where I want to hand off a socket to a library, but then for debugging purposes I want to log everything sent or received over the socket by the library. I'd rather not have to change the library, and I can register a 'data' handler to get the incoming data, but what about the outoing?
var orig_write = socket.write;socket.write = function(data) { this.emit.call(this, 'write', data); return orig_write.apply(this, arguments);};
socket.on('write', function (data) {
// yay});
// pass socket on to library now