PHP code example of znframework / package-socket
1. Go to this page and download the library: Download znframework/package-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/ */
znframework / package-socket example snippets
le: server.php
$socket = ZN\Socket\Server::run('tcp', '127.0.0.1', 8080);
$socket->live(function($socket)
{
switch( $socket->read() )
{
case 'exit' : $socket->write('Goodbye!'); return;
case 'write': $socket->write('Run write command.'); break;
case 'read' : $socket->write('Run read command.'); break;
default : return;
}
});
# File: client.php
$socket = ZN\Socket\Client::run('tcp', '127.0.0.1', 8080);
$socket->write($command);
echo $socket->read();