PHP sending message via TCP/IP

╄→гoц情女王★ 提交于 2019-12-10 15:38:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!