Example #1
0
    }
    /* Send instructions. */
    $msg = "\nWelcome to the Chimaera Vehicle Control Server. \n" . "To quit, type 'quit'. To shut down the server type 'kill'.\n";
    socket_write($msgsock, $msg, strlen($msg));
    do {
        if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
            echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
            break 2;
        }
        if (!($buf = trim($buf))) {
            continue;
        }
        if ($buf == 'quit') {
            break;
        }
        if ($buf == 'kill') {
            socket_close($msgsock);
            break 2;
        }
        $talkback = "PHP: You said '{$buf}'.\n";
        socket_write($msgsock, $talkback, strlen($talkback));
        $serial->sendMessage($buf);
        echo "{$buf}\n";
    } while (true);
    socket_close($msgsock);
} while (true);
socket_close($sock);
$serial->closePort();
?>