当前位置:Gxlcms > PHP教程 > PHPsocket实现readInt和readString以及和Java端对接

PHPsocket实现readInt和readString以及和Java端对接

时间:2021-07-01 10:21:17 帮助过:4人阅读

java:

DataOutputStream out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));out.writeInt("REWQTY".getBytes().length);out.write("REWQTY".getBytes());out.close();//php端是阻塞的,除非close

php:

functionreadInt($sock)
{$buf = socket_read($sock,4);
   if ($buf){
       return unpack('N',$buf)[1];
   }else{
       thrownewException();
   }
}

functionreadString($socket) {$n = readInt($socket);
  return socket_read($socket, $n);
}

echo readString($sock,$l);
echo"\n";

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了PHP socket实现 readInt 和 readString 以及和Java端对接,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

  • 人气教程排行