国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

@walkor 大大 一個socket_select() 通信問題

var

這是php官網(wǎng)sokcet_select()下的一個例子,我運行發(fā)現(xiàn)一個問題,就是多個客戶端telnet 方式連接時,如果一個客戶端輸入消息但是沒有按回車發(fā)送出去,那么其他的telnet客戶端的消息發(fā)出去都不會廣播到其他telnet。
@walkor 如何加判斷解決這一問題呢 求科普

<?php
$port = 8888;

$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

socket_set_option($sock, SOL_SOCKET, SO_REUSEADDR, 1);

socket_bind($sock, 0, $port);

socket_listen($sock);

$clients = array($sock);

$addr = '';
$prot = '';
while (true) {

    $read = $clients;

    if (socket_select($read, $write = NULL, $except = NULL, null) < 1) {

        continue;
    }

    if (in_array($sock, $read)) {

        $clients[] = $newsock = socket_accept($sock);

        socket_getpeername($newsock, $addr, $port);

        socket_write($newsock, "welcome clients:" . $addr . " port:" . $port . "\n" . "thre are " . (count($clients) - 1) . ' clients connected to the server' . "\n");

        echo "New client connected: {$addr}\n";

        $key = array_search($sock, $read);
        unset($read);
    }

    foreach ($read as $read_sock) {

        $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ);

        if ($data === false || $data == '') {

            $key = array_search($read_sock, $clients);
            unset($clients);
            echo "client disconnected.\n";

            continue;
        }

        $data = trim($data);

        if (!empty($data)) {

            foreach ($clients as $send_sock) {

                if ($send_sock == $sock || $send_sock == $read_sock)
                    continue;

                socket_write($send_sock, $data . "\n");

            }

        }

    }
}

socket_close($sock);
3411 1 0
1個回答

walkor 打賞

一步一步打日志看下

  • 暫無評論
年代過于久遠,無法發(fā)表回答
??