您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

高手来,关于php中socket的有关问题

2025/9/18 23:03:01发布25次查看
高手来,关于php中socket的问题!
一个硬件往服务器端口上发送数据(抓包软得到的是正确的16进制),通过抓包软件抓取的数据是正常的(16进制),然而通过php的socket接受到的数据(通过转换后也是16进制,未转换是乱码),下面贴上代码,请高手帮忙看下哪里错了。为什么php的socket获取的数据和抓包软件获取的不一样
通过抓包软件获取的正确代码是(16进制的):fa 01 01 ff aa 03 00 01 00 0b 00 00 00 a3
通过php socket获得的数据(通过dechex(),ord()转换后的,和软件抓取的不一样,是错误的):fa 7 25 2 fa 2 0 9 f6 4 2c 88 fa 1
下面贴上php的socket代码:
php code= $max_users) { $reject = server full. try again later.\n; } //将当前客户端连接放如socket_select选择 $connections[$i] = $newconn; //输入的连接资源缓存容器 $writefds[$i] = $newconn; //连接不正常 if ($reject) { $close[$i] = true; } else { echo welcome to the php chat server!\n; } //初始化当前连接读取内容的缓存容器 $input[$i] = ; continue; } //客户端连接 $i = (int)$rfd; //读取 $tmp = @socket_read($rfd, 14, php_normal_read); if (!$tmp) { //读取不到内容 print connection closed on socket $i\n; close($i); continue; } $input[$i] .= $tmp; $tmp = substr($input[$i], -1); /*if ($tmp != \r && $tmp != \n) { // no end of line, more data coming continue; }*/ $line = trim($input[$i]); $input[$i] = ; echo 'client >>'.$line.\r\n; $data=str_split($line); print_r($data); echo \r\n; //$data = explode(\t,$line); //$data=str_split($data); foreach($data as $v){ echo dechex(ord($v)).\t; } echo \r\n; socket_getpeername($connections[$i],&$remoteip,&$remoteport);echo $remoteip.\r\n;echo $remoteport.\r\n;//$data=str_split($buffer);//print_r($data);$str=\xfa\x01\x01\xff\xaa\xaa\x00\x01\x00\x00\x00\x00\x00\x01; socket_send($connections[$i],$str,strlen($str),0); } foreach ($writefds as $wfd) { $i = (int)$wfd; $w = socket_write($wfd, hello); } } }function close($i){ global $connections, $input, $close; socket_shutdown($connections[$i]); socket_close($connections[$i]); unset($connections[$i]); unset($input[$i]); unset($close[$i]);}?>

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product