ws_write()


Trasmitting data to the designated websocket TCP session(ID)

Description

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

Parameters

Return Value

On success returns the transmitted bytes, 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)
  {
    $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