#!/usr/bin/env php
<?php

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

use Inhere\WebSocket\WSInterface;
use Inhere\WebSocket\Server\ServerFactory;
use Inhere\WebSocket\Server\ServerInterface;

define('PROJECT_PATH', __DIR__);

$options = [
    // 'debug' => true,
    'name' => 'ws',
    'driver' => 'streams',
];

$svr = ServerFactory::make('', 9501, $options);
//$svr = ServerFactory::parseOptMake($options);

$svr->on('open', function (ServerInterface $svr) {
    $svr->send('OPEN: welcome!');
});

$svr->on(WSInterface::ON_MESSAGE, function (ServerInterface $svr, $data) {
    $svr->send("You input: $data");
});

$svr->start();
