Home >Backend Development >PHP Tutorial >PHP socket implementation and Java side readFully docking

PHP socket implementation and Java side readFully docking

WBOY
WBOYOriginal
2016-07-29 08:57:441142browse

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>
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the connection between PHP socket implementation and Java-side readFully, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn