コード例 #1
0
ファイル: server.php プロジェクト: gpis88ce/Gpis88ce
function handle_input(&$server, &$client, $input)
{
    // You probably want to sanitize your inputs here
    $trim = trim($input);
    // Trim the input, Remove Line Endings and Extra Whitespace.
    if (strtolower($trim) == "quit") {
        SocketServer::socket_write_smart($client->socket, "Oh... Goodbye...");
        // Give the user a sad goodbye message, meany!
        $server->disconnect($client->server_clients_index);
        // Disconnect this client.
        return;
        // Ends the function
    }
    $output = strrev($trim);
    // Reverse the String
    SocketServer::socket_write_smart($client->socket, $output);
    // Send the Client back the String
    SocketServer::socket_write_smart($client->socket, "String? ", "");
    // Request Another String
}
コード例 #2
0
function handle_input($server, $client, $input)
{
    $data = trim($input);
    if (strtolower($data) == "quit") {
        // User Wants to quit the server
        SocketServer::socket_write_smart($client->socket, "Oh... Goodbye...");
        // Give the user a sad goodbye message, meany!
        $server->disconnect($client->server_clients_index);
        // Disconnect this client.
        return;
    }
    $deviceId = substr($data, 1, 10);
    $messageCode = substr($data, 11, 2);
    $date = substr($data, 13, 6);
    $time = substr($data, 19, 6);
    $inputVoltage = substr($data, 25, 3);
    $currentLoad = substr($data, 28, 5);
    $status = substr($data, 33, 3);
    $lowCutSetPoint = substr($data, 36, 3);
    $highCutSetPoint = substr($data, 39, 3);
    $overLoadSetPoint = substr($data, 42, 2);
    global $conn;
    $sql = "INSERT INTO audit(device_id, time, date, input_voltage, current_load, status, low_cut_set, high_cut_set, message_code, overload_set) values(" . "'" . $deviceId . "'" . "," . "'" . htmlspecialchars($time) . "'" . "," . "'" . htmlspecialchars($date) . "'" . "," . "'" . htmlspecialchars($inputVoltage) . "'" . "," . "'" . htmlspecialchars($currentLoad) . "'" . "," . "'" . htmlspecialchars($status) . "'" . "," . "'" . htmlspecialchars($lowCutSetPoint) . "'" . "," . "'" . htmlspecialchars($highCutSetPoint) . "'" . "," . "'" . htmlspecialchars($messageCode) . "'" . "," . "'" . htmlspecialchars($overLoadSetPoint) . "'" . ")";
    if ($conn->query($sql) === TRUE) {
        $success = "Auditing Done";
        echo $success;
        ob_flush();
        flush();
    } else {
        $error = "Error: " . $conn->error;
        echo $error;
        ob_flush();
        flush();
    }
    //SocketServer::socket_write_smart($client->socket,$output); // Send the Client back the String
    //SocketServer::socket_write_smart($client->socket,"a? ",""); // Request Another String
}