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


TypeScript Duplex.emit方法代碼示例

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


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

示例1: function

 client.on('close', function(reason) {
   stream.push(null);
   stream.emit('close');
   log.debug('client went away');
 });
開發者ID:MisterTea,項目名稱:TidalWave,代碼行數:5,代碼來源:sharejs-handler.ts

示例2: connect

  /**
   * Starts the connection establishment to the proxy and destination.
   * @param existing_socket Connected socket to use instead of creating a new one (internal use).
   */
  public connect(existing_socket?: Duplex) {
    this._onDataReceived = (data: Buffer) => this.onDataReceived(data);
    this._onClose = () => this.onClose();
    this._onError = (err: Error) => this.onError(err);
    this._onConnect = () => this.onConnect();

    // Start timeout timer (defaults to 30 seconds)
    const timer = setTimeout(
      () => this.onEstablishedTimeout(),
      this._options.timeout || DEFAULT_TIMEOUT
    );

    // check whether unref is available as it differs from browser to NodeJS (#33)
    if (timer.unref && typeof timer.unref === 'function') {
      timer.unref();
    }

    // If an existing socket is provided, use it to negotiate SOCKS handshake. Otherwise create a new Socket.
    if (existing_socket) {
      this._socket = existing_socket;
    } else {
      this._socket = new net.Socket();
    }

    // Attach Socket error handlers.
    this._socket.once('close', this._onClose);
    this._socket.once('error', this._onError);
    this._socket.once('connect', this._onConnect);
    this._socket.on('data', this._onDataReceived);

    this.state = SocksClientState.Connecting;
    this._receiveBuffer = new ReceiveBuffer();

    if (existing_socket) {
      this._socket.emit('connect');
    } else {
      (this._socket as net.Socket).connect(
        this._options.proxy.port,
        this._options.proxy.host || this._options.proxy.ipaddress
      );
      if (
        this._options.set_tcp_nodelay !== undefined &&
        this._options.set_tcp_nodelay !== null
      ) {
        (this._socket as net.Socket).setNoDelay(
          !!this._options.set_tcp_nodelay
        );
      }
    }

    // Listen for established event so we can re-emit any excess data received during handshakes.
    this.prependOnceListener('established', info => {
      setImmediate(() => {
        if (this._receiveBuffer.length > 0) {
          const excessData = this._receiveBuffer.get(
            this._receiveBuffer.length
          );

          info.socket.emit('data', excessData);
        }
        info.socket.resume();
      });
    });
  }
開發者ID:JoshGlazebrook,項目名稱:socks,代碼行數:68,代碼來源:socksclient.ts


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