ws_read()


读取websocket session的接收数据

Description

int ws_read(int $tcp_id, string &$rbuf [, int $rlen = MAX_STRING_LEN])

Parameters

Return Value

成功时读取的数据大小(字节数),失败时 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)
  {
    ws_read(0, $rbuf);   // reading data from the socket
    if(strlen($rbuf) > 0)
    {
      hexdump($rbuf);
      $rbuf = "";
    }
    sleep(1);
  }
}
?>

See also