PHP implementation code for sending and receiving hexadecimal data through Socket_PHP tutorial

WBOY
Release: 2016-07-21 14:59:05
Original
755 people have browsed it

Recently I was doing related content about Socket communication under PHP, and found that many people on the Internet are learning about how to send and receive in hexadecimal. After some research, the code is as follows. Welcome to comment.

Copy code The code is as follows:

$sendStr = '30 32 30 34 03 30 33 '; // Hexadecimal data

$sendStrArray = str_split(str_replace(' ', '', $sendStr), 2); // Convert hexadecimal data into an array of two

$socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname("tcp")); // Create Socket

if (socket_connect($socket, "192.168.1.100", 8080)) { //Connect
for ($j = 0; $j < count($sendStrArray); $j++) {
socket_write($socket, chr(hexdec($sendStrArray[$j]))); // Send data group by group
}

$receiveStr = "";
$receiveStr = socket_read($socket, 1024, PHP_BINARY_READ); // Receive data in binary format
$receiveStrHex = bin2hex($receiveStr); // will 2 Convert hexadecimal data to hexadecimal

                                                                                                                                                                                                          echo "client:" .



http://www.bkjia.com/PHPjc/328168.html

www.bkjia.com

true

TechArticleRecently I was doing related content about Socket communication under PHP and found that many people on the Internet are learning how to perform hexadecimal processing. After some research on sending and receiving, the code is as follows. Welcome to try it out. Copy the code The code is like...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template