/examples/close.js

http://github.com/OpenRTMFP/ArcusNode · JavaScript · 27 lines · 17 code · 4 blank · 6 comment · 2 complexity · de3c240746bd50ebe3445707ae13e245 MD5 · raw file

  1. /**
  2. * Close a NetConnection
  3. */
  4. var ArcusNode = require('../lib/arcus_node.js');
  5. //Create a new ArcusNode instance
  6. var arc = ArcusNode.createServer();
  7. arc.on('connect', function(nc, options, username, password){
  8. nc.on('close', function(){
  9. console.log('Connection ' + nc.id + ' was closed.');
  10. });
  11. // Close the connection after 30 seconds
  12. setTimeout(function() {
  13. nc.close(function(success){
  14. if(success){
  15. console.log('Connection close attempt successful.');
  16. } else {
  17. console.log('ERROR: Connection could not be closed.');
  18. }
  19. });
  20. }, 3000);
  21. });
  22. //Start the server
  23. arc.run();