Products

中文

中文

  • Pipy 文档
  • Introduction
    • 概述
    • 概念
  • Getting Started
    • 构建和安装
    • 快速入门
    • 获取帮助
  • Release
    • 发布历史
      • 0.10.0-1
      • 0.22.0-31
      • 0.30.0
      • 0.50.0
  • Tutorial
    • 01 你好
    • 02 回显
    • 03 代理
    • 04 路由
    • 05 负载均衡
    • 06 配置
    • 07 插件
  • Operating
    • 开发控制台
    • CLI
    • Pipy Repo
      • 介绍
      • 快速开始
      • 演示
      • REST API
  • Reference
    • API
      • Configuration
        • acceptHTTPTunnel()
        • acceptProxyProtocol()
        • acceptSOCKS()
        • acceptTLS()
        • admin()
        • branch()
        • branchMessage()
        • branchMessageStart()
        • chain()
        • compress()
        • compressHTTP()
        • connect()
        • connectHTTPTunnel()
        • connectProxyProtocol()
        • connectSOCKS()
        • connectTLS()
        • decodeBGP()
        • decodeDubbo()
        • decodeHTTPRequest()
        • decodeHTTPResponse()
        • decodeMQTT()
        • decodeMultipart()
        • decodeRESP()
        • decodeThrift()
        • decodeWebSocket()
        • decompress()
        • decompressHTTP()
        • deframe()
        • demux()
        • demuxHTTP()
        • detectProtocol()
        • dummy()
        • dump()
        • encodeBGP()
        • encodeDubbo()
        • encodeHTTPRequest()
        • encodeHTTPResponse()
        • encodeMQTT()
        • encodeRESP()
        • encodeThrift()
        • encodeWebSocket()
        • exec()
        • exit()
        • export()
        • fork()
        • handleData()
        • handleMessage()
        • handleMessageBody()
        • handleMessageEnd()
        • handleMessageStart()
        • handleStreamEnd()
        • handleStreamStart()
        • handleTLSClientHello()
        • import()
        • insert()
        • link()
        • listen()
        • loop()
        • mux()
        • muxHTTP()
        • onEnd()
        • onStart()
        • pack()
        • pipeline()
        • print()
        • read()
        • repeat()
        • replaceData()
        • replaceMessage()
        • replaceMessageBody()
        • replaceMessageEnd()
        • replaceMessageStart()
        • replaceStreamEnd()
        • replaceStreamStart()
        • replay()
        • serveHTTP()
        • split()
        • task()
        • tee()
        • throttleConcurrency()
        • throttleDataRate()
        • throttleMessageRate()
        • to()
        • use()
        • wait()
        • watch()
      • Data
        • from()
        • Data()
        • push()
        • shift()
        • shiftTo()
        • shiftWhile()
        • size
        • toArray()
      • Hessian
        • decode()
        • encode()
      • JSON
        • decode()
        • encode()
        • parse()
        • stringify()
      • Message
        • body
        • head
        • Message()
        • tail
      • MessageEnd
        • MessageEnd()
        • payload
        • tail
      • MessageStart
        • head
        • MessageStart()
      • Netmask
        • base
        • bitmask
        • broadcast
        • contains()
        • decompose()
        • first
        • hostmask
        • ip
        • last
        • mask
        • Netmask()
        • next()
        • size
        • version
      • StreamEnd
        • error
        • StreamEnd()
      • URL
        • auth
        • hash
        • host
        • hostname
        • href
        • URL()
        • origin
        • password
        • path
        • pathname
        • port
        • protocol
        • query
        • search
        • searchParams
        • username
      • URLSearchParams
        • get()
        • getAll()
        • URLSearchParams()
        • set()
        • toObject()
      • XML
        • Node
          • attributes
          • children
          • name
          • Node()
        • decode()
        • encode()
        • parse()
        • stringify()
      • algo
        • Cache
          • clear()
          • get()
          • Cache()
          • remove()
          • set()
        • HashingLoadBalancer
          • add()
          • HashingLoadBalancer()
          • next()
        • LeastWorkLoadBalancer
          • LeastWorkLoadBalancer()
          • next()
          • set()
        • LoadBalancer
          • allocate()
          • LoadBalancer()
          • provision()
          • schedule()
        • LoadBalancerResource
          • free()
          • target
        • Quota
          • consume()
          • current
          • initial
          • Quota()
          • produce()
          • reset()
        • RoundRobinLoadBalancer
          • RoundRobinLoadBalancer()
          • next()
          • set()
        • URLRouter
          • add()
          • find()
          • URLRouter()
        • hash()
        • uuid()
      • console
        • debug()
        • error()
        • info()
        • log()
        • warn()
      • crypto
        • Certificate
          • issuer
          • Certificate()
          • subject
          • subjectAltNames
        • CertificateChain
          • CertificateChain()
        • Cipher
          • final()
          • Cipher()
          • update()
        • Decipher
          • final()
          • Decipher()
          • update()
        • Hash
          • digest()
          • Hash()
          • update()
        • Hmac
          • digest()
          • Hmac()
          • update()
        • JWK
          • isValid
          • JWK()
        • JWT
          • header
          • isValid
          • JWT()
          • payload
          • verify()
        • PrivateKey
          • PrivateKey()
        • PublicKey
          • PublicKey()
        • Sign
          • Sign()
          • sign()
          • update()
        • Verify
          • Verify()
          • update()
          • verify()
      • http
        • Agent
          • new()
          • request()
        • Directory
          • new()
          • serve()
      • logging
        • BinaryLogger
          • log()
          • BinaryLogger()
          • toFile()
          • toHTTP()
          • toStderr()
          • toStdout()
          • toSyslog()
        • JSONLogger
          • log()
          • JSONLogger()
          • toFile()
          • toHTTP()
          • toStderr()
          • toStdout()
          • toSyslog()
        • TextLogger
          • log()
          • TextLogger()
          • toFile()
          • toHTTP()
          • toStderr()
          • toStdout()
          • toSyslog()
      • os
        • env
        • readDir()
        • readFile()
        • stat()
        • unlink()
        • writeFile()
      • pipy()
        • exit()
        • load()
        • restart()
        • solve()
      • stats
        • Counter
          • decrease()
          • increase()
          • Counter()
          • withLabels()
          • zero()
        • Gauge
          • decrease()
          • increase()
          • Gauge()
          • set()
          • withLabels()
          • zero()
        • Histogram
          • Histogram()
          • observe()
          • withLabels()
          • zero()

    Configuration.connect()

    Description

    Appends a connect filter to the current pipeline layout.

    A connect filter establishes a TCP connection to a remote host.

    • INPUT - Data stream to send to the host.
    • OUTPUT - Data stream received from the host.
    connectDataData

    A connect filter does the following:

    • It establishes a TCP or UDP connection to a remote host specified in the target parameter
    • Input Data stream to the filter is sent to that host after the connection is established
    • Data stream received from that host comes out from the filter's output

    Target address

    The target address to connect to is given by the target parameter. It can be a string in form of "<host>:<port>" or a function that returns that string, where host can be an IP address or a domain name and port must be a valid port number.

    When using an IPv6 address, wrap it inside a pair of brackets. For example, "[::1]:8080".

    Outbound data buffer

    No limit is set to how fast input Data can go into a connect filter, but an outgoing TCP connection does have a limit depending on the network condition. When outgoing traffic is too slow and incoming traffic is too fast, Data will be backed up in the filter's internal buffer.

    By default, the buffer can grow unlimitedly. You can set a limit to how much data is allowed to stay in memory by option bufferLimit in the options parameter. It can be a number in bytes or a string with a unit suffix such as 'k', 'm', 'g' and 't'.

    When data in the buffer goes over that limit, the overflowed data is discarded and you will see an error message from the standard error:

    Outbound: xxx to host = xxx port = nnn buffer overflow, size = nnn

    Syntax

    pipy()
    .pipeline()
    .connect(target)
    pipy()
    .pipeline()
    .connect(
    () => getTarget()
    )
    pipy()
    .pipeline()
    .connect(
    () => getTarget(),
    {
    bufferLimit,
    retryCount,
    retryDelay,
    connectTimeout,
    readTimeout,
    writeTimeout,
    idleTimeout,
    }
    )

    Parameters

    connect(target, options?)

    target

    The target to connect to, in form of "<host>:<port>", or a function that returns the target.

    options?

    Options including:

    • protocol - Protocol to use. Can be "TCP" or "UDP". Default is "TCP".
    • bind - A string in form of "<IP>:<port>" providing the local IP and port to bind to or a function that returns that.
    • congestionLimit - Size threshold of data backlog in output buffer where congestion feedback starts. Can be a number in bytes or a string with a unit suffix such as 'k', 'm', 'g' and 't'.
    • bufferLimit - Maximum size of data allowed to stay in output buffer as a result of insufficient outbound bandwidth. Can be a number in bytes or a string with a unit suffix such as 'k', 'm', 'g' and 't'.
    • retryCount - How many times it should retry connection after a failure, or -1 for the infinite retries. Defaults to 0.
    • retryDelay - Time duration to wait between connection retries. Defaults to 0.
    • connectTimeout - Timeout while connecting. Can be a number in seconds or a string with one of the time unit suffixes such as s, m or h. Defaults to no timeout.
    • readTimeout - Timeout while reading. Can be a number in seconds or a string with one of the time unit suffixes such as s, m or h. Defaults to no timeout.
    • writeTimeout - Timeout while writing. Can be a number in seconds or a string with one of the time unit suffixes such as s, m or h. Defaults to no timeout.
    • idleTimeout - Duration before connection is closed due to no active reading or writing. Can be a number in seconds or a string with one of the time unit suffixes such as s, m or h. Defaults to 1 minute.
    • keepAlive - Enable sending of keep-alive messages on TCP connections. Defaults to true.
    • noDelay - If set, disable the Nagle algorithm. Defaults to true.
    Return Value

    The same Configuration object.

    Example

    pipy()
    .listen(8000) // Accept connections via port 8000
    .dump('>>>') // Dump all outgoing data
    .connect(
    'localhost:8080' // Connect to localhost:8080
    )
    .dump('<<<') // Dump all received data

    See Also


    © 2024, Flomesh Team.       ICP备案/许可证号:辽ICP备2023014827号