java:
<code>DataInputStream stream = <span>new</span> DataInputStream(<span>new</span> BufferedInputStream(socket.getInputStream())); <span>int</span> i= stream.readInt(); <span>byte</span>[] b = <span>new</span><span>byte</span>[i]; stream.readFully(b); System.<span>out</span>.println(<span>new</span> String(b));</code>
php:
<code><span><span>function</span><span>writeInt</span><span>(<span>$socket</span>, <span>$i</span>)</span> {</span><span>$data</span> = pack(<span>'N'</span>, <span>$i</span>); socket_write(<span>$socket</span>, <span>$data</span>); } writeInt(<span>$sock</span>,strlen(<span>"ZXCV"</span>)); socket_write(<span>$sock</span>,<span>"ZXCV"</span>,strlen(<span>"ZXCV"</span>)); </code>
以上就介绍了PHP socket实现和Java端readFully对接,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。