PHP uses Socket to send and receive hexadecimal data. Recently, I am working on Socket communication in php. I found that many people on the network are learning how to send and receive data in hexadecimal mode. I have studied the code below. You are welcome to make a decision. Copy the code. for example, I recently did something about Socket communication in php. I found that many people on the network are learning how to send and receive data in hexadecimal mode. I have studied the code below. You are welcome to make a brick.
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 two arrays.
$ Socket = socket_create (AF_INET, SOCK_STREAM, getprotobyname ("tcp"); // Create a 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 group-by-group data
}
$ ReceiveStr = "";
$ ReceiveStr = socket_read ($ socket, 1024, PHP_BINARY_READ); // receives data in binary mode.
$ ReceiveStrHex = bin2hex ($ receiveStr); // Convert binary data into hexadecimal data
Echo "client:". $ receiveStrHex;
}
Socket_close ($ socket); // Close the Socket
?>
Bytes. Code such...