Closed ghost closed 8 years ago
The stream you get from accept(true)
is a stream to the socks client that is requesting a connection. If you want to get data from the destination, just use accept(true)
and manually create the socket to the destination (and pipe the two together if you want). For example:
var net = require('net');
socks.createServer(function(info, accept, deny) {
var clientSocket = accept(true);
var destSocket = new net.Socket();
destSocket.on('connect', function(d) {
console.log('destSocket connected');
// Also let data flow between client and its requested destination
destSocket.pipe(clientSocket).pipe(destSocket);
});
destSocket.on('data', function(d) {
console.log('destSocket data: %j', d);
});
destSocket.connect(info.dstPort, info.dstAddr);
});
You may also not want to accept(true)
the request until destSocket
has connected first (e.g. deny()
ing in destSocket.on('error', ...)
Thank you! It took me a little bit, but I'm fairly comfortable with the library now. :)
Forgive me if I'm missing anything particularly obvious, but I'm not sure how I'd go about intercepting data returned by the destination address.
I tried socket.read(), but that seems to indefinitely return null. Any tips?