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

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

问题描述

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

Im try to send a Message from PHP Website via TCP/IP to an Arduino.

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

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.

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

Already tried to limit the messagelength to 2bytes, but without any success.

推荐答案

尝试在try - catch块内添加.



    try {

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

看看您可能会遇到什么异常.

To see what exception you may get.

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

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