nl_tokens: Create a websocket client and set it off at the server
pl_tokens: function createClient ( host , port , concurrent , frequency , duration , gen , iteration ) { var auth = defaults . auth var getMessage = defaults . getMessage emitter . emit ( 'start' ) if ( typeof gen . authenticate === 'function' ) { auth = gen . authenticate } if ( typeof gen . clientIterateMessage === 'function' ) { getMessage = gen . clientIterateMessage } /**
     * Once auth is complete, this actually initiates the client
     * @method  postAuth
     * @async
     * @private
     * @param   {object} err Error from auth, if any
     * @param   {object} cookies Any cookies to pass through to the socket object
     * @param   {string} user The username used to login
     * @param   {string} pass The password used to login
     * @returns {object} undefined
     */ var postAuth = function ( err , cookies , user , pass ) { ++ clientsAttempted if ( err ) { emitter . emit ( 'error' , err ) if ( clientsAttempted === concurrent && _intervals . length === 0 ) { emitter . emit ( 'end' ) } return } var socketUrl = gen . getSocketURL ( host , port , cookies , user , pass ) || host + ':' + port var socket = io ( socketUrl , { multiplex : false } ) . on ( 'connect' , function ( ) { emitter . emit ( 'client-connected' ) if ( typeof gen . events . connect === 'function' ) { gen . events . connect ( 'connect' , cookies , user , pass , { } , socket , emitter ) } Object . keys ( gen . events ) . forEach ( function ( eventName ) { socket . on ( eventName , function ( data ) { gen . <mask> [ eventName ] . call ( null , eventName , cookies , user , pass , data , socket , emitter ) } ) } ) var sendMessage = function ( ) { var message = getMessage ( cookies , user , pass ) if ( ! Array . isArray ( message ) ) { message = [ message ] } for ( var i = 0 , len = message . length ; i < len ; i ++ ) { if ( message [ i ] ) { socket . json . send ( message [ i ] ) emitter . emit ( 'message' , message [ i ] ) } } } _intervals . push ( setInterval ( sendMessage , frequency ) ) setTimeout ( function ( ) { clearInterval ( _intervals . pop ( ) ) socket . emit ( 'disconnect' ) emitter . emit ( 'disconnect' ) socket . close ( ) if ( _intervals . length === 0 ) { done ( ) } } , duration ) } ) . on ( 'connect_error' , function ( err ) { emitter . emit ( 'error' , err ) if ( clientsAttempted === concurrent && _intervals . length === 0 ) { emitter . emit ( 'end' ) } } ) } auth ( host , port , iteration , postAuth ) }