Assuming "write" is the only function call that sends data (not sure if 
stream piping or anything calls something internal instead... in which case 
you'd want to use a "through" stream), you can hook that directly by 
overriding it on your instance of a socket, something like this should work:

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

Hope this helps!
  Jimb

On Friday, October 30, 2015 at 10:45:35 AM UTC-7, Dave Horton wrote:
>
> 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?
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/85d77ac8-9eff-4cc6-ba77-f8f820f202b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to