PHP Classes

File: vendor/react/socket/examples/01-echo-server.php

Recommend this page to a friend!
  Classes of Stanley Aloh   Tic Tac Toe Multiplayer   vendor/react/socket/examples/01-echo-server.php   Download  
File: vendor/react/socket/examples/01-echo-server.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Tic Tac Toe Multiplayer
Manage the interactions ofTic-Tac-Toe game players
Author: By
Last change:
Date: 9 days ago
Size: 1,166 bytes
 

Contents

Class file image Download
<?php

// Just start this server and connect to it. Everything you send to it will be
// sent back to you.
//
// $ php examples/01-echo-server.php 8000
// $ telnet localhost 8000
//
// You can also run a secure TLS echo server like this:
//
// $ php examples/01-echo-server.php tls://127.0.0.1:8000 examples/localhost.pem
// $ openssl s_client -connect localhost:8000
//
// You can also run a Unix domain socket (UDS) server like this:
//
// $ php examples/01-echo-server.php unix:///tmp/server.sock
// $ nc -U /tmp/server.sock

use React\EventLoop\Factory;
use
React\Socket\Server;
use
React\Socket\ConnectionInterface;

require
__DIR__ . '/../vendor/autoload.php';

$loop = Factory::create();

$server = new Server(isset($argv[1]) ? $argv[1] : 0, $loop, array(
   
'tls' => array(
       
'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem')
    )
));

$server->on('connection', function (ConnectionInterface $connection) {
    echo
'[' . $connection->getRemoteAddress() . ' connected]' . PHP_EOL;
   
$connection->pipe($connection);
});

$server->on('error', 'printf');

echo
'Listening on ' . $server->getAddress() . PHP_EOL;

$loop->run();