當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript stream.Duplex類代碼示例

本文整理匯總了TypeScript中stream.Duplex的典型用法代碼示例。如果您正苦於以下問題:TypeScript Duplex類的具體用法?TypeScript Duplex怎麽用?TypeScript Duplex使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Duplex類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: removeInternalSocketHandlers

 /**
  * Removes internal event listeners on the underlying Socket.
  */
 private removeInternalSocketHandlers() {
   // Pauses data flow of the socket (this is internally resumed after 'established' is emitted)
   this._socket.pause();
   this._socket.removeListener('data', this._onDataReceived);
   this._socket.removeListener('close', this._onClose);
   this._socket.removeListener('error', this._onError);
   this._socket.removeListener('connect', this.onConnect);
 }
開發者ID:JoshGlazebrook,項目名稱:socks,代碼行數:11,代碼來源:socksclient.ts

示例2: sendSocks5CommandRequest

  /**
   * Sends Socks v5 final handshake request.
   */
  private sendSocks5CommandRequest() {
    const buff = new SmartBuffer();

    buff.writeUInt8(0x05);
    buff.writeUInt8(SocksCommand[this._options.command]);
    buff.writeUInt8(0x00);

    // ipv4, ipv6, domain?
    if (net.isIPv4(this._options.destination.host)) {
      buff.writeUInt8(Socks5HostType.IPv4);
      buff.writeBuffer(ip.toBuffer(this._options.destination.host));
    } else if (net.isIPv6(this._options.destination.host)) {
      buff.writeUInt8(Socks5HostType.IPv6);
      buff.writeBuffer(ip.toBuffer(this._options.destination.host));
    } else {
      buff.writeUInt8(Socks5HostType.Hostname);
      buff.writeUInt8(this._options.destination.host.length);
      buff.writeString(this._options.destination.host);
    }
    buff.writeUInt16BE(this._options.destination.port);

    this._nextRequiredPacketBufferSize =
      SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHeader;
    this._socket.write(buff.toBuffer());
    this.state = SocksClientState.SentFinalHandshake;
  }
開發者ID:JoshGlazebrook,項目名稱:socks,代碼行數:29,代碼來源:socksclient.ts

示例3: sendSocks4InitialHandshake

  /**
   * Sends initial Socks v4 handshake request.
   */
  private sendSocks4InitialHandshake() {
    const userId = this._options.proxy.userId || '';

    const buff = new SmartBuffer();
    buff.writeUInt8(0x04);
    buff.writeUInt8(SocksCommand[this._options.command]);
    buff.writeUInt16BE(this._options.destination.port);

    // Socks 4 (IPv4)
    if (net.isIPv4(this._options.destination.host)) {
      buff.writeBuffer(ip.toBuffer(this._options.destination.host));
      buff.writeStringNT(userId);
      // Socks 4a (hostname)
    } else {
      buff.writeUInt8(0x00);
      buff.writeUInt8(0x00);
      buff.writeUInt8(0x00);
      buff.writeUInt8(0x01);
      buff.writeStringNT(userId);
      buff.writeStringNT(this._options.destination.host);
    }

    this._nextRequiredPacketBufferSize =
      SOCKS_INCOMING_PACKET_SIZES.Socks4Response;
    this._socket.write(buff.toBuffer());
  }
開發者ID:JoshGlazebrook,項目名稱:socks,代碼行數:29,代碼來源:socksclient.ts

示例4:

 const invocationCallback = (errorValue, successValue) => {
     connection.end(JSON.stringify({
         result: successValue,
         errorMessage: errorValue && (errorValue.message || errorValue),
         errorDetails: errorValue && (errorValue.stack || null)
     }));
 };
開發者ID:Niaro,項目名稱:JavaScriptServices,代碼行數:7,代碼來源:SocketNodeInstanceEntryPoint.ts

示例5: function

 client.on('message', function(data) {
   log.debug('c->s ', JSON.stringify(data));
   if (data['a']=='sub' || data['a']=='bs') {
     if (data['a']=='sub') {
       // User is subscribing to a new document
       log.debug("Got new sub");
       document = data['d'];
     } else { // data['a']=='bs'
       var collectionDocumentVersionMap = data['s'];
       var numCollections = Object.keys(collectionDocumentVersionMap).length;
       if (numCollections != 1) {
         log.error({message:"Zero or more than one collection not expected",value:numCollections});
         client.stop();
         return;
       }
       var cName = Object.keys(collectionDocumentVersionMap)[0];
       var numDocuments = Object.keys(collectionDocumentVersionMap[cName]).length;
       if (numDocuments != 1) {
         log.error({message:"Zero or more than one document not expected",value:numDocuments});
         client.stop();
         return;
       }
       var docName = Object.keys(collectionDocumentVersionMap[cName])[0];
       document = docName;
     }
     mongoStore.get(sessionId, function(err, session) {
       if (err) {
         log.error(err);
         client.stop();
         return;
       }
       if (!session) {
         log.error({message:"Tried to get session that doesn't exist",value:rawSessionCookie});
         client.stop();
         return;
       }
       var userId = session.passport.user;
       if (!userId) {
         log.error({message:"Tried to get userId that doesn't exist",value:session});
         client.stop();
         return;
       }
       AuthHelper.userIdCanAccessPageId(userId, document, function(canAccess) {
         if (!canAccess) {
           client.stop();
           return;
         }
         pageConnectionMap[document] = pageConnectionMap[document] ?
           pageConnectionMap[document]+1 :
           1;
         log.info(pageConnectionMap[document] + " CLIENTS CONNECTED TO " + document);
         stream.push(data);
       });
     });
   } else {
     stream.push(data);
   }
 });
開發者ID:MisterTea,項目名稱:TidalWave,代碼行數:58,代碼來源:sharejs-handler.ts

示例6: Error

            const invocationCallback = (errorValue, successValue) => {
                if (hasInvokedCallback) {
                    throw new Error('Cannot supply more than one result. The callback has already been invoked,'
                        + ' or the result stream has already been accessed');
                }

                hasInvokedCallback = true;
                connection.end(JSON.stringify({
                    result: successValue,
                    errorMessage: errorValue && (errorValue.message || errorValue),
                    errorDetails: errorValue && (errorValue.stack || null)
                }));
            };
開發者ID:chris-herring,項目名稱:JavaScriptServices,代碼行數:13,代碼來源:SocketNodeInstanceEntryPoint.ts

示例7: sendSocks5UserPassAuthentication

  /**
   * Sends Socks v5 user & password auth handshake.
   *
   * Note: No auth and user/pass are currently supported.
   */
  private sendSocks5UserPassAuthentication() {
    const userId = this._options.proxy.userId || '';
    const password = this._options.proxy.password || '';

    const buff = new SmartBuffer();
    buff.writeUInt8(0x01);
    buff.writeUInt8(Buffer.byteLength(userId));
    buff.writeString(userId);
    buff.writeUInt8(Buffer.byteLength(password));
    buff.writeString(password);

    this._nextRequiredPacketBufferSize =
      SOCKS_INCOMING_PACKET_SIZES.Socks5UserPassAuthenticationResponse;
    this._socket.write(buff.toBuffer());
    this.state = SocksClientState.SentAuthentication;
  }
開發者ID:JoshGlazebrook,項目名稱:socks,代碼行數:21,代碼來源:socksclient.ts

示例8: _closeSocket

  /**
   * Closes and destroys the underlying Socket. Emits an error event.
   * @param err { String } An error string to include in error event.
   */
  private _closeSocket(err: string) {
    // Make sure only one 'error' event is fired for the lifetime of this SocksClient instance.
    if (this.state !== SocksClientState.Error) {
      // Set internal state to Error.
      this.state = SocksClientState.Error;

      // Destroy Socket
      this._socket.destroy();

      // Remove internal listeners
      this.removeInternalSocketHandlers();

      // Fire 'error' event.
      this.emit('error', new SocksClientError(err, this._options));
    }
  }
開發者ID:JoshGlazebrook,項目名稱:socks,代碼行數:20,代碼來源:socksclient.ts

示例9: sendSocks5InitialHandshake

  /**
   * Sends initial Socks v5 handshake request.
   */
  private sendSocks5InitialHandshake() {
    const buff = new SmartBuffer();
    buff.writeUInt8(0x05);

    // We should only tell the proxy we support user/pass auth if auth info is actually provided.
    // Note: As of Tor v0.3.5.7+, if user/pass auth is an option from the client, by default it will always take priority.
    if (this._options.proxy.userId || this._options.proxy.password) {
      buff.writeUInt8(2);
      buff.writeUInt8(Socks5Auth.NoAuth);
      buff.writeUInt8(Socks5Auth.UserPass);
    } else {
      buff.writeUInt8(1);
      buff.writeUInt8(Socks5Auth.NoAuth);
    }

    this._nextRequiredPacketBufferSize =
      SOCKS_INCOMING_PACKET_SIZES.Socks5InitialHandshakeResponse;
    this._socket.write(buff.toBuffer());
    this.state = SocksClientState.SentInitialHandshake;
  }
開發者ID:JoshGlazebrook,項目名稱:socks,代碼行數:23,代碼來源:socksclient.ts


注:本文中的stream.Duplex類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。