PHP code example of krypt0nn / bpn

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

    

krypt0nn / bpn example snippets




PN\BPN;
use BPN\Networking\Endpoint;
use BPN\Encoding\ECC;
use BPN\Data\Packet;

$keypair = ECC::generateKeyPair();

BPN::configure ([
    'public_key'  => $keypair['public'],
    'private_key' => $keypair['private']
]);

BPN::get()->send (
    Endpoint::format('server address'),
    Packet::performEvent('hello-world', 'Hello, World!')
);



PN\BPN;
use BPN\Networking\Endpoint;
use BPN\Encoding\ECC;

$keypair = ECC::generateKeyPair();

BPN::configure ([
    'public_key'  => $keypair['public'],
    'private_key' => $keypair['private']
]);

BPN::on('hello-world', fn (Packet $packet) => echo $packet->data['data'] . PHP_EOL);

while (true)
    BPN::get()->update();



PN\BPN;
use BPN\Networking\Endpoint;
use BPN\Networking\Tunneling\Tunnel;
use BPN\Encoding\ECC;

$keypair = ECC::generateKeyPair();

BPN::configure ([
    'public_key'  => $keypair['public'],
    'private_key' => $keypair['private']
]);

$tunnel = Tunnel::create(Endpoint::format('server address'));

if ($tunnel === null)
    die ('Tunnel creation error');

else while (true)
{
    $message = readline ('> ');

    $tunnel->send ($message);
}



PN\BPN;
use BPN\Networking\Endpoint;
use BPN\Networking\Tunneling\Tunnel;

$keypair = ECC::generateKeyPair();

BPN::configure ([
    'public_key'  => $keypair['public'],
    'private_key' => $keypair['private']
]);

while (!($tunnel = Tunnel::listen(Endpoint::local())));

while (true)
{
    $tunnel->update (function ($data)
    {
        echo $data . PHP_EOL;
    });
}



PN\BPN;
use BPN\Networking\DNS;
use BPN\Networking\DNS\Record;
use BPN\Data\Packet;

$keypair = ECC::generateKeyPair();

BPN::configure ([
    'public_key'  => $keypair['public'],
    'private_key' => $keypair['private']
]);

DNS::searchRecords ('client uuid', function (Record $record, Packet $packet)
{
    echo 'Client with endpoint '. $packet->author_endpoint->toString() .
         ' found client we wanted to find'.
         ' and his endpoint is '. $record->endpoint()->toString() . PHP_EOL;

    // if you want to not to receive another records
    // you can return false from this callback
    // return false;
});



use BPN\BPN;

$keypair = ECC::generateKeyPair();

BPN::configure ([
    'public_key'  => $keypair['public'],
    'private_key' => $keypair['private']
]);

# Add broadcast handler for incoming data
BPN::onBroadcast(function ($data)
{
    echo '['. $data['author'] .'] '. $data['message'] . PHP_EOL;
});

# Broadcast data
BPN::broadcast ([
    'author'  => 'aboba',
    'message' => 'Hello, World!'
]);