How to Send and Receive Hexadecimal Data
Receiving Hexadecimal Data
When data is received, you can use the function bin2hex($data) to convert the data into hexadecimal.
Sending Hexadecimal Data
Before sending data, use hex2bin($data) to convert the hexadecimal data into binary for sending.
Example:
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('text://0.0.0.0:8080');
$worker->onMessage = function(TcpConnection $connection, $data){
// Get hexadecimal data
$hex_data = bin2hex($data);
// Send hexadecimal data to the client
$connection->send(hex2bin($hex_data));
};
Worker::runAll();