void Connection::pipe(TcpConnection $target_connection)


Imports the data stream of the current connection into the target connection. Built-in traffic control. This method is very useful for TCP proxy.

Example: TCP Proxy

use Workerman\Worker;
use Workerman\Connection\AsyncTcpConnection;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker('tcp://');
$worker->count = 12;

// After the TCP connection is established
$worker->onConnect = function(TcpConnection $connection)
    // Establish an asynchronous connection to the local port 80
    $connection_to_80 = new AsyncTcpConnection('tcp://');
    // Set the data from the current client connection to be directed to the connection on port 80
    // Set the data returned from the 80 port connection to be directed to the client connection
    // Execute the asynchronous connection

// Run the worker