java:
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));out.writeInt("REWQTY".getBytes().length);out.write("REWQTY".getBytes());out.close();//php端是阻塞的,除非closephp:
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 ').text(i)); }; $numbering.fadeIn(1700); }); });
以上就介绍了PHP socket实现 readInt 和 readString 以及和Java端对接,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。











