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

PHP socket implementation and Java side readFully docking

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 08:57:44
Original
1180 people have browsed it

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>
Copy after login

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>
Copy after login
').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.

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template