I am writing a simple tunneling proxy.
The basic code is as follows:

var server = net.createServer(function(socket) {
    socket.on('data', function(data) {
        if (first_data) {
            if (d.substring(0, 8) == "connect") {
                host = 'abc';
                port = 8081;
            }
            else {
                 host = 'def';
                 port = 8082;
            }
            proxy = net.connect({host: host, port: port}, function() {
                proxy.write(data);
            }
            proxy.on('data', function(data) {
                //if (socket.destroyed) { // Why is the socket destroyed 
here?
                //}
                //else {
                    socket.write(data);
                //}
            });
            proxy.on('end', function(e) {
                //console.log('proxy end');
                socket.end();
            });
            proxy.on('error', function(e) {
                console.dir('proxy error ' + e);
            });
            first_data = 0;
        }
        else {
            proxy.write(data);
        }
    });
    socket.on('end', function () {
        proxy.end();
    });
    socket.on('error', function(e) {
        console.dir(e); // This is where the error is printed.
    });
});
server.listen(8080, function() {
});
server.on('error', function(e) {
    console.dir(e);
});

If I load the server with 10 requests, everything works fine. But if I load 
it to 500 requests, I start seeing "This socket is closed" error. I have 
verified that socket.on('close'/ 'end') was called only after this error is 
printed.

So I am trying to understand who and why closed this socket and why the 
socket.on close/ end was not called for the same?

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to