首頁 >後端開發 >php教程 >PHP socket實作與Java端readFully對接

PHP socket實作與Java端readFully對接

WBOY
WBOY原創
2016-07-29 08:57:441142瀏覽

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); }); });

以上就介紹了PHP socket實作和Java端readFully對接,包含了面向的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn