PHP code example of varion / transport

1. Go to this page and download the library: Download varion/transport library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

varion / transport example snippets




declare(strict_types=1);

use Varion\Transport\Driver\Stream\StreamDriver;
use Varion\Transport\Transport;

$transport = new Transport(new StreamDriver());

$conn = $transport->connect('tcp://127.0.0.1:8080');
$conn->write("ping\n");
$response = $conn->read(1024);
$conn->close();



declare(strict_types=1);

use Varion\Transport\Driver\Stream\StreamDriver;
use Varion\Transport\Transport;

$transport = new Transport(new StreamDriver());

$listener = $transport->listen('tcp://127.0.0.1:8080');

while ($conn = $listener->accept()) {
    $data = $conn->read(1024);
    $conn->write("HTTP/1.0 200 OK\\r\\nContent-Length: 2\\r\\n\\r\\nOK");
    $conn->close();
}