<?php
error_reporting(E_ALL);

/* 允许脚本挂起等待连接。 */
set_time_limit(0);

/* 打开绝对隐式输出刷新 */
ob_implicit_flush();


// wireshark抓包java 字节流 的十六进制
$hex_str = 'b7c7d5fdb3a3bfa8c3dc20b3a4b6c8b2bbb6d4'; //请求数据

$byte_str = pack("H*", $hex_str); // H 十六进制字符串,高位在前, pack 把数据装入一个二进制字符串

$string = iconv("gb2312", "utf-8", $byte_str);

var_dump($string);  //测试是否正常解析,下面用socket请求




$address = '42.194.**.**';
$port = 6677;

$res = sendSocketMsg($address,$port,$byte_str,1);
$res = iconv("gb2312", "utf-8", $res);
var_dump($res);


function sendSocketMsg($host, $port, $str, $back = 0)
{
    $socket = socket_create(AF_INET, SOCK_STREAM, 0);
    if ($socket < 0) {
        return false;
    }
    $result = @socket_connect($socket, $host, $port);
    if ($result == false) {
        return false;
    }
    socket_write($socket, $str, strlen($str));
    if ($back != 0) {
        $input = socket_read($socket, 1024);
        socket_close($socket);
        return $input;
    } else {
        socket_close($socket);
        return true;
    }
}

 

 

 

posted on 2021-10-07 18:34  上善若水-随  阅读(72)  评论(0编辑  收藏  举报