一个http服务内部有异步tcp客户端 tcp onMessage 如何返回给http服务呢?

zjcyjj
<?php
$http_worker = new Worker ('http://0.0.0.0:8089'); 

$http_worker->onWorkerStart = function($http_worker) {
    //子进程启动后,建立tcp客户端,
    $inner_tcp_client = new AsyncTcpConnection('tcp://127.0.0.1:19640'); 

    $inner_tcp_client->onConnect = function( $inner_tcp_client)
    {     
        $reg_info = '';
        $inner_tcp_client->send($reg_info);
    };

    $inner_tcp_client->onMessage = function( $inner_tcp_client, $data) {     
        if ($parse_uid == '_server'){
            //如何返回给http_worker?
            //$http_worker ->send("replay"); //这样对吗?
    };

    $inner_tcp_client->connect();
    $http_worker->inner_tcp_client = $inner_tcp_client;
};

$http_worker->onMessage = function ($connection, $data) use ($http_worker) {
    $http_worker->inner_tcp_client->send($data);
};

Worker::runAll();
?>
1101 1 0
1个回答

walkor 打赏
<?php
$http_worker = new Worker ('http://0.0.0.0:8089'); 

$http_worker->onMessage = function($http_connection, $request) {
    //子进程启动后,建立tcp客户端,
    $inner_tcp_client = new AsyncTcpConnection('tcp://127.0.0.1:19640'); 

    $inner_tcp_client->onConnect = function( $inner_tcp_client)
    {     
        $reg_info = '';
        $inner_tcp_client->send($reg_info);
    };

    $inner_tcp_client->onMessage = function( $inner_tcp_client, $data) use ($http_connection) {     
        $inner_tcp_client->close();
        $http_connection->send('.....');
    };

    $inner_tcp_client->connect();
};

Worker::runAll();
  • 暂无评论
年代过于久远,无法发表回答
×
🔝