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.
$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
true