zoukankan      html  css  js  c++  java
  • swoole和erlang通信测试

    直接用docker跑环境

    docker pull xlight/docker-php7-swoole
    docker run -it -v ~/Projects/php/swoole:/workdir -p 9501:9501 xlight/docker-php7-swoole /bin/bash
    php workdir/app_server.php start

    app_server.php

    <?php
    
    $serv = new swoole_server("0.0.0.0", 9501);
    
    $serv->set(array(
        'package_max_length' => 8192,
        'open_length_check'=> true,
        'package_length_offset' => 0,
    
        //大小端默认,组包方式{packet, 2}
        // 'package_body_offset' => 2,
        // 'package_length_type' => 'n'
    
        //大小端默认,组包方式{packet, 4}
        'package_body_offset' => 4,
        'package_length_type' => 'N'
    ));
    
    $port = $serv->listen('127.0.0.1', 9502, SWOOLE_SOCK_UDP);
    $port->on('packet', function($serv, $data, $addr){
        var_dump($serv, $data, $addr);
    });
    
    $serv->on('connect', function ($serv, $fd, $from_id){
        echo "[#".posix_getpid()."]	Client@[$fd:$from_id]: Connect.
    ";
    });
    
    $serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
        echo "[#".$serv->worker_id."]	Client[$fd]: $data
    ";
        if ($serv->send($fd, "hello
    ") == false)
        {
            echo "error
    ";
        }
    });
    
    $serv->on('close', function ($serv, $fd, $from_id) {
        echo "[#".posix_getpid()."]	Client@[$fd:$from_id]: Close.
    ";
    });
    
    $serv->start();

    参数参考地址

  • 相关阅读:
    初探Remoting双向通信(三)
    MySQL主从复制
    MySQL锁机制
    mySql索引
    连接池
    JDBC
    数据库建表、约束、索引
    Oracle和SQL简介
    Stream API 和 注解
    lambda表达式
  • 原文地址:https://www.cnblogs.com/ziyouchutuwenwu/p/5775577.html
Copyright © 2011-2022 走看看