读取websocket session的指定大小数据
int ws_readn(int $tcp_id, string &$rbuf, int $rlen)
成功时读取数据大小(字节数),失败时0
<?php
include "/lib/sn_tcp_ws.php";
// configuring a websocket and waiting for a connection
ws_setup(0, "my_path", "my_proto");
$rbuf = "";
while(1)
{
if(ws_state(0) == TCP_CONNECTED)
{
/* If there are data equal to or more than 100,
it copies 100 bytes of data to the $rbuf and returns 100 */
ws_readn(0, $rbuf, 10);
if(strlen($rbuf) > 0)
{
hexdump($rbuf);
$rbuf = "";
}
sleep(1);
}
}
?>