PHP implementation code for sending and receiving hexadecimal data via socket _php Tutorial

Source: Internet
Author: User
Recently in PHP to do about the socket communication related content, found that many people on the network to understand how to carry out 16, research, the code below, welcome to shoot bricks.
Copy CodeThe code is as follows:
$SENDSTR = ' 30 32 30 34 03 30 33 '; 16 Binary data

$sendStrArray = Str_split (Str_replace (",", $sendStr), 2); Converting 16 of binary data into two arrays

$socket = Socket_create (Af_inet, Sock_stream, Getprotobyname ("TCP")); Create socket

if (Socket_connect ($socket, "192.168.1.100", 8080)) {//connection
for ($j = 0; $j < count ($sendStrArray); $j + +) {
Socket_write ($socket, Chr (Hexdec ($sendStrArray [$j])); Send data by group
}

$RECEIVESTR = "";
$RECEIVESTR = Socket_read ($socket, 1024x768, php_binary_read); Receive data in 2 binary mode
$receiveStrHex = Bin2Hex ($RECEIVESTR); Convert 2 binary data to 16 binary

echo "Client:". $receiveStrHex;
}
Socket_close ($socket); Close socket
?>

http://www.bkjia.com/PHPjc/328168.html www.bkjia.com true http://www.bkjia.com/PHPjc/328168.html techarticle recently in PHP to do about the socket communication related content, found that many people on the network to understand how to carry out 16, research, the code below, welcome to shoot bricks. Copy code code such as ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.