PHP code example of expressif / socket
1. Go to this page and download the library: Download expressif/socket 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/ */
expressif / socket example snippets
pressif\Socket\Server;
use Expressif\Socket\Client;
$endpoint = 'tcp://127.0.0.1:1337';
echo "Starting the server at $endpoint\n";
$server = new Server($endpoint);
$server->on('connection', function($client) use() {
$client->on('data', function($name) use($client) {
$client->write('Hello '.$name)->close();
});
});
$c = new Client($endpoint);
$c->send('James Bond')->on('data', function($greetings) {
echo "<< $greetings\n";
});