ws_write()


通过websocket session发送数据

Description

int ws_write(int $tcp_id, int/string $wbuf [, int $wlen = MAX_STRING_LEN])

Parameters

Return Value

成功时发送数据大小(字节 数),失败时0

Example

<?php
include "/lib/sn_tcp_ws.php";
$rwbuf = "";
// configuring a websocket and waiting for a connection
ws_setup(0, "my_path", "my_proto");
while(1)
{
  if(ws_state(0) == TCP_CONNECTED)
  {
    $rwlen = ws_read(0, $rwbuf);  // reading data from the websocket
    if($rwlen > 0)
      ws_write(0, $rwbuf);        // transmitting the received data
  }
  sleep(1);
}
?>

See also