keepAlive_error.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. var tunnel = require('../');
  2. var helper = require('./server');
  3. // Keep alive example
  4. // this example demonstrates the keepAlive option.
  5. // keepAlive will reuse the connections
  6. // note the "tunnelKeepAlive.close();" at the end.
  7. // this step is required to finish execution nicely
  8. var configA = {
  9. host: '127.0.0.1',
  10. username: process.env.USER,
  11. dstPort: 8000,
  12. localPort: 7000, // Use keepAlive:true to keep the tunnel open.
  13. keepAlive: true
  14. };
  15. var tunnelKeepAlive = tunnel(configA, function () {
  16. console.log('Tunnel open');
  17. helper.createClient(7000, '127.0.0.1', console.log);
  18. helper.createClient(7000, '127.0.0.1', console.log);
  19. helper.createClient(7000, '127.0.0.1', console.log).on('close', function () {
  20. helper.createClient(7000, '127.0.0.1', console.log).on('close', function () {
  21. helper.createClient(7000, '127.0.0.1', console.log).on('close', function () {
  22. setTimeout(function () {
  23. // Call tunnel.close() to shutdown the server.
  24. console.log('TRYING TO CLOSE');
  25. tunnelKeepAlive.close();
  26. }, 2000);
  27. });
  28. });
  29. });
  30. }).on('error', function (e) {
  31. console.log('error', e);
  32. });