当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Duplex.write方法代码示例

本文整理汇总了TypeScript中stream.Duplex.write方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Duplex.write方法的具体用法?TypeScript Duplex.write怎么用?TypeScript Duplex.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stream.Duplex的用法示例。


在下文中一共展示了Duplex.write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。