PHP code example of msst / byte-buffer

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

    

msst / byte-buffer example snippets




SST\ByteBuffer\Buffer;

$text1 = 'channel_one';
$text2 = "This is a utf8 test message. 😄";

$buffer = new Buffer(4 + 1 + 4 + strlen($text1) + strlen($text2));
$buffer->writeInt32($buffer->length());
$buffer->writeInt8(0x1);
$buffer->writeInt32(strlen($text1));
$buffer->write($text1);
$buffer->writeUtf8($text2);

$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());