Blogger Information
Blog 9
fans 0
comment 0
visits 11824
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php socket发送十六进制指令
何书鹏的博客
Original
1544 people have browsed it

十六进制转换:


PHP 操作串口或socket时以16进制发送

"10 EE 2D 0F"

16进制字符串写法:

"\x10\xEE\x2D\x0F"


$sendStr = hex2bin(preg_replace('# #', '', "10 EE 2D 0F"))


socket发送:


  $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);  // 创建Socket


        if (socket_connect($socket, "127.0.0.1", 7002)) {  //连接

            socket_write($socket, $sendStr);  

            $receiveStr = "";

            $receiveStr = socket_read($socket, 1024, PHP_BINARY_READ);  // 采用2进制方式接收数据

            $receiveStrHex = bin2hex($receiveStr);  // 将2进制数据转换成16进制

            echo "client:" . $receiveStrHex;

        }

        socket_close($socket);  // 关闭Socket

————————————————

版权声明:本文为CSDN博主「lkj4565」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/lkj4565/article/details/79076763


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments