+
95
-

swoole tcpserver如何在onreceive处理http请求返回html网页?

php

请问swoole tcpserver如何在onreceive处理http请求返回html网页?

网友回复

+
15
-
<?php
$server = new Swoole\Server("0.0.0.0", 9503);

$server->on('connect', function ($server, $fd) {
    echo "connection open: {$fd}\n";
});

$server->on('receive', function ($server, $fd, $reactor_id, $data) {

    $response = new Response();

    $_htmlstr = "hello world 你好 朋友";

    $response->withHeader('Content-Type', 'text/html;charset=utf-8')
    ->withHeader('Content-Length', strlen($_htmlstr))
    ->withBody($_htmlstr);

    $server->send($fd, $response->getPackage());


    $ser...

点击查看剩余70%

+
15
-
<?php
$server = new Swoole\WebSocket\Server("0.0.0.0", 9514, SWOOLE_BASE);

$tcp = $server->listen("0.0.0.0", 9515, SWOOLE_SOCK_TCP);

$server->on("open", function ($serv, $req) {
    echo "new WebSocket Client, fd={$req->fd}\n";
});

$server->on("message", function ($serv, $frame) {
    echo "receive from {$frame->fd}:{$fr...

点击查看剩余70%

我知道答案,我要回答