예제 #1
0
<?php

include __DIR__ . '/../vendor/autoload.php';
/**
 * Class DemoServer
 */
class DemoServer extends \FastD\Swoole\Server\Udp
{
    /**
     * @param swoole_server $server
     * @param $data
     * @param $client_info
     * @return mixed
     */
    public function doPacket(swoole_server $server, $data, $client_info)
    {
        echo $data . PHP_EOL;
        return 'hello tcp';
    }
}
DemoServer::run('tcp://127.0.0.1:9527');
/**
 * 以上写法和以下写法效果一致
 *
 * $test = new DemoServer();
 * $test->start();
 */
예제 #2
0
파일: console.php 프로젝트: JanHuang/swoole
 */
class DemoServer extends \FastD\Swoole\Server\Tcp
{
    /**
     * @param swoole_server $server
     * @param $fd
     * @param $data
     * @param $from_id
     * @return mixed
     */
    public function doWork(swoole_server $server, $fd, $data, $from_id)
    {
        return 'hello tcp';
    }
}
$server = new DemoServer('tcp://0.0.0.0:9527');
$input = new \FastD\Console\Input\Input(null, new \FastD\Console\Input\InputDefinition());
$action = $input->getFirstArgument();
if ($input->hasOption(['d', 'daemon'])) {
    $server->daemonize();
}
switch ($action) {
    case 'start':
        $server->start();
        break;
    case 'stop':
        $server->shutdown();
        break;
    case 'reload':
        $server->reload();
        break;
예제 #3
0
파일: watch.php 프로젝트: JanHuang/swoole
include __DIR__ . '/../vendor/autoload.php';
class DemoServer extends \FastD\Swoole\Server\Tcp
{
    /**
     * @param swoole_server $server
     * @param $fd
     * @param $data
     * @param $from_id
     * @return mixed
     */
    public function doWork(swoole_server $server, $fd, $data, $from_id)
    {
        return 'hello tcp';
    }
}
$server = new DemoServer('tcp://0.0.0.0:9527');
$argv = $_SERVER['argv'];
$argv[1] = isset($argv[1]) ? $argv[1] : 'status';
switch ($argv[1]) {
    case 'start':
        $server->start();
        break;
    case 'stop':
        $server->shutdown();
        break;
    case 'reload':
        $server->reload();
        break;
    case 'watch':
        $server->watch([__DIR__ . '/listen_files']);
        break;
예제 #4
0
/**
 * Created by PhpStorm.
 * User: janhuang
 * Date: 16/1/18
 * Time: 下午9:47
 * Github: https://www.github.com/janhuang
 * Coding: https://www.coding.net/janhuang
 * SegmentFault: http://segmentfault.com/u/janhuang
 * Blog: http://segmentfault.com/blog/janhuang
 * Gmail: bboyjanhuang@gmail.com
 * WebSite: http://www.janhuang.me
 */
include __DIR__ . '/../vendor/autoload.php';
/**
 * Class DemoServer
 */
class DemoServer extends \FastD\Swoole\Server\Tcp
{
    public function doWork(swoole_server $server, $fd, $data, $from_id)
    {
        echo $data . PHP_EOL;
        return 'hello tcp';
    }
}
DemoServer::run('tcp://0.0.0.0:9527');
/**
 * 以上写法和以下写法效果一致
 *
 * $test = new DemoServer();
 * $test->start();
 */