ws_read_line()


Reading data every lines (ending with CR+LF) from the websocket session

Description

int ws_read_line(int $tcp_id, string &$rbuf)

Parameters

Return Value

the number of byte to read

Example

<?php
<?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)
  {
    ws_read_line(0, $rbuf);   // Read one line of data
    if(strlen($rbuf) > 0)
    {
      hexdump($rbuf);
      $rbuf = "";
    }
    sleep(1);
  }
}
?>

See also