1. Go to this page and download the library: Download imafaz/esock 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/ */
imafaz / esock example snippets
use Esock\Esock;
$esok = new Esock;
$ip = '91.107.153.188';
$port = 9000;
$esock->initServer($ip, $port) or die($esock->lastError);
while (true) {
$client = $esock->accept() or die($esock->lastError);
$input = $esock->read($client) or die($esock->lastError);
echo $input;
$esock->write($client, 'ok') or die($esock->lastError);
$esock->close($client) or die($esock->lastError);
}
$ip = '91.107.153.188';
$port = 9000;
$esock = new Esock;
$client = $esock->initClient($ip, $port) or die($esock->lastError);
$esock->write($client, 'its a realy test') or die($esock->lastError);
$input = $esock->read($client) or die($esock->lastError);
echo $input;
// $esock->initServer($ip, $port);
// example:
$esock->initServer($ip, $port) or die($esock->lastError);
// $esock->initClient($ip, $port);
//example:
$client = $esock->initClient($ip, $port) or die($esock->lastError);
// $esock->accept();
// example:
$client = $esock->accept() or die($esock->lastError);