src/js/lib/RTRemoteServer.js
/**
   * open rpc tcp socket server receive rpc messages and return messages
   * @param {string} rpcHost the tcp bind ip address
   * @param {number|int} rpcPort the tcp bind port
   * @return {Promise<RTRemoteServer>} the remote server
   */
open rpc tcp socket server receive rpc messages and return messages
@param {string} rpcHost the tcp bind ip address
@param {number|int} rpcPort the tcp bind port
@return {Promise} the remote server
open rpc tcp socket server receive rpc messages and return messages @param { string } rpcHost the tcp bind ip address @param { number|int } rpcPort the tcp bind port @return { Promise } the remote server
openRpcSocketServer(rpcHost, rpcPort) {
    const that = this;
    return new Promise((resolve, reject) => {
      that.rpcSocketServer = net.createServer((socket) => {
        const transport = new RTRemoteTCPTransport(socket);
        RTRemoteProtocol.create(transport, true).then((protocol) => {
          protocol.rtRemoteServer = that;
        });
        socket.on('error', (err) => {
          logger.error(err);
          socket.destroy();
        });
        socket.on('close', () => {
          logger.info('a client connection closed');
        });
      });
      this.rpcSocketServer.on('error', (err) => {
        logger.error(`unexpected rpc server error:\n${err.stack}`);
        reject(new RTException(err.message));
      });
      this.rpcSocketServer.listen(rpcPort, rpcHost, () => {
        that.rpcHost = that.rpcSocketServer.address().address;
        that.rpcPort = that.rpcSocketServer.address().port;
        logger.info(`rpc socket server bind succeed, ${that.rpcHost}:${that.rpcPort}`);
        resolve(that);
      });
    });
  }
openRpcSocketServer ( rpcHost , rpcPort ) { const that = this ; return new Promise ( ( resolve , reject ) => { that . rpcSocketServer = net . createServer ( ( socket ) => { const transport = new RTRemoteTCPTransport ( socket ) ; RTRemoteProtocol . create ( transport , true ) . then ( ( protocol ) => { protocol . rtRemoteServer = that ; } ) ; socket . on ( 'error' , ( err ) => { logger . error ( err ) ; socket . destroy ( ) ; } ) ; socket . on ( 'close' , ( ) => { logger . info ( 'a client connection closed' ) ; } ) ; } ) ; this . rpcSocketServer . on ( 'error' , ( err ) => { logger . error ( ` \n ${ err . stack } ` ) ; reject ( new RTException ( err . message ) ) ; } ) ; this . rpcSocketServer . listen ( rpcPort , rpcHost , ( ) => { that . rpcHost = that . rpcSocketServer . address ( ) . address ; that . rpcPort = that . rpcSocketServer . address ( ) . port ; logger . info ( ` ${ that . rpcHost } ${ that . rpcPort } ` ) ; resolve ( that ) ; } ) ; } ) ; }
open rpc tcp socket server receive rpc messages and return messages
 @param {string} rpcHost the tcp bind ip address
 @param {number|int} rpcPort the tcp bind port
 @return {Promise<RTRemoteServer>} the remote server
open rpc tcp socket server receive rpc messages and return messages @param { string } rpcHost the tcp bind ip address @param { number|int } rpcPort the tcp bind port @return { Promise<RTRemoteServer > } the remote server
// socket already created, no exceptions need catch for create protocol // only log error and close this socket, server still need continue run