Slide 57
Slide 57 text
class Client {
public function __construct($host,$port) {
$this->EventLoop = React\EventLoop\Factory::create();
$fp = stream_socket_client("tcp://{$host}:{$port}");
if(!$fp) throw new \Exception(“unable to connect {$host}:{$port}”);
stream_set_blocking($fp,false);
$this->Socket = new React\Socket\Connection($fp,$this->EventLoop);
$this->Socket->on('data',[$this,'OnDataIn']);
$this->Socket->on('close',[$this,'OnDisconnect']);
return;
}