PHP 通过 TCP/IP 发送消息 [英] PHP sending message via TCP/IP

查看:33
本文介绍了PHP 通过 TCP/IP 发送消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过 TCP/IP 从 PHP 网站向 Arduino 发送消息.

使用以下代码,我可以从 php 网站发送消息

问题是,第一次调用网站时,消息没有立即传递.在网站刷新几次后,消息就到达了,但逻辑如此之多,就像网站刷新量一样.

已经尝试将消息长度限制为 2 字节,但没有成功.

解决方案

尝试在 try - catch 块中添加.

<前>尝试 {} 捕获(异常 $e){回声 $e->getMessage();}

看看你可能会得到什么例外.

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.

解决方案

Try adding inside a try - catch block.


    try {

    } catch (Exception $e) {
     echo $e->getMessage();
    }

To see what exception you may get.

这篇关于PHP 通过 TCP/IP 发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆