ws_txfree()


Getting free buffer space of the designated webscoket TCP session's TX buffer

Description

int ws_txfree(int $tcp_id)

Parameters

Return Value

On success, it returns free TX buffer length of the websocket TCP session, otherwise 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)
  {
    // Reading the data as many as the websocket TX buffer free or less
    $rwlen = ws_read(0, $rwbuf, ws_txfree(0));
    if($rwlen > 0)
      ws_write(0, $rwbuf);   // transmitting the received data
  }
  sleep(1);
}
?>

See also