ws_readn()


Reading the designated number of byte from the websocket session

Description

int ws_readn(int $tcp_id, string &$rbuf, int $rlen)

Parameters

Return Value

If there are data equal to or more than the $rlen in the websocket receiving buffer, it returns the $rlen, otherwise returns 0

Example

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

See also