PHP code example of clue / icmp-react

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

    

clue / icmp-react example snippets


$factory = new Clue\React\Icmp\Factory();
$icmp = $factory->createIcmp4();

$loop = $factory->getLoop();

// place your ICMP calls here, see below...

// important: run the loop in order to actually do anything
$loop->run();

$loop = React\EventLoop\Factory::create();
$factory = new Clue\React\Icmp\Factory($loop);

$icmp->ping($remote, $timeout);

$icmp->ping('github.com', 3.0)->then(function ($time) {
    echo 'Success after ' . $time . ' seconds';
}, function(Exception $error) {
    echo 'Nope, there was an error';
});

$icmp->on('message', function (Clue\React\Icmp\Message $message, $peerAddress) {
    echo 'Message type ' . $message->getType() . ' from ' . $peerAddress . PHP_EOL;
});

$message = new Clue\React\Icmp\Message($type, $code, $checksum, $header, $payload)

$factory = new Clue\React\Icmp\MessageFactory();
$message = $factory->createMessagePing();

$icmp->sendMessage($message, '127.0.0.1');

$ sudo php examples/ping.php www.google.com