问题
Im try to send a Message from PHP Website via TCP/IP to an Arduino.
With following code i'm able to send a message from php website
<?php
$errno = NULL;
$error = NULL;
if (!$handle = @fsockopen("192.168.188.24", "49419", $errno, $error, 10))
{
die("Fehler (".$errno."): ".$error);
}
fwrite($handle, "ON\r\n");
fclose($handle);
?>
The problem is, when calling the website for the first time, the message doesnt get delivered immediatly. Just after some refreshes of the website, the message arrives, but logical so many times like amount of website refreshes.
Already tried to limit the messagelength to 2bytes, but without any success.
回答1:
Try adding inside a try - catch
block.
try { } catch (Exception $e) { echo $e->getMessage(); }
To see what exception you may get.
来源:https://stackoverflow.com/questions/35178912/php-sending-message-via-tcp-ip