• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript stream.Duplex类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript stream.PassThrough类代码示例发布时间:2022-05-25
下一篇:
TypeScript strands.Strands类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap