PHP code example of denpa / php-levin

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

    

denpa / php-levin example snippets




use Denpa\Levin;

$vars = [
    'network_id' => 'somenetwork',
];

Levin\connection($ip, $port, $vars)->connect(
    function ($bucket, $connection) {
        if ($bucket->isRequest('supportflags', 'timedsync', 'ping')) {
            // respond to supportflags, timedsync and ping requests
            // to keep the connection open
            $connection->write($bucket->response());
        }

        if ($bucket->isResponse('handshake')) {
            // send ping request to the server after
            // receiving handshake response
            $connection->write(Levin\request('ping'));
        }

        if ($bucket->isResponse('ping')) {
            // dump server response to the console
            var_dump($bucket->getPayload());

            // returning false closes connection
            return false;
        }
    }
);