PHP code example of rubyqorn / socket

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

    

rubyqorn / socket example snippets




onsillium\QonsilliumSocket;
use Qonsillium\ServerSocket;

$server = new QonsilliumSocket('config.yaml');
$server->runServer(function(ServerSocket $socket) {
    echo $socket->send('Hello from server!');
});



onsillium\QonsilliumSocket;
use Qonsillium\ClientSocket;

$server = new QonsilliumSocket('config.yaml');
$server->runClient(function(ClinetSocket $socket) {
    echo $socket->send('Hello from client!');
});

 john@doe:/workdir/$ php server.php
 john@doe:/workdir/$ php client.php

 

namespace App;

use Qonsillium\QonsilliumSocket
use Qonillium\ClientSocket

class SocketMessagePrinter extends QonsilliumSocket
{
    public function handleServerSocketMessage(string $myMessage)
    {
        $serverMessage = $this->runClient(function(ClientSocket $client) use ($myMessage) {
            return $client->send($myMessage);
        });

        if ($serverMessage === 'Hello from server!') {
            // handle this action
        }
    }
}