PHP code example of trafficcophp / bytebuffer

1. Go to this page and download the library: Download trafficcophp/bytebuffer 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/ */

    

trafficcophp / bytebuffer example snippets




rafficCophp\ByteBuffer\ByteBuffer;

$channel = 'channel_one';
$message = 'php';

$buffer = new ByteBuffer(4 + 1 + 4 + strlen($channel) + strlen($message));
$buffer->writeInt32BE($buffer->length(), 0);
$buffer->writeInt8(0x1, 4);
$buffer->writeInt32BE(strlen($channel), 5);
$buffer->write($channel, 9);
$buffer->write($message, 9 + strlen($channel));

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, '127.0.0.1', 3542);

socket_write($socket, (string) $buffer, $buffer->length());