SendWebSocket (Socket function): Difference between revisions
m (→Usage notes) |
|||
(One intermediate revision by the same user not shown) | |||
Line 36: | Line 36: | ||
</table> | </table> | ||
Sending a control frame always forces a flush of the TCP output buffer. A close or a ping are the only valid control frames. | |||
==Examples== | ==Examples== | ||
The following example | The following example sends a text message to the WebSocket client. | ||
<p class="code">... | <p class="code">... | ||
Latest revision as of 19:53, 29 July 2024
Send Web Socket framed message (Socket class)
[Introduced in Model 204 7.8 βeta]
This page is under construction.
Syntax
[%number =] socket:SendWebSocket( string, number, boolean)
Syntax terms
socket | Socket object | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
string | string | ||||||||||||||||||
number | number is an op code indicating the type of web socket frame. Numbers 0-7 are non-control frames. Numbers 8-15 are control frames. Control frames are always sent immediately and cannot be fragmented. Specifying a reserved code will cause immediate request cancellation.
| ||||||||||||||||||
boolean | Boolean value that indicates whether to mask the data with a masking key. The default is not to mask the data. Masking is done using an internally generated masking key. |
Sending a control frame always forces a flush of the TCP output buffer. A close or a ping are the only valid control frames.
Examples
The following example sends a text message to the WebSocket client.
... %sock = WebSocket if %sock is null then audittext Socket closed, status is {$STATUSD} stop end if %op = %sock:ReceiveWebSocket(%wsi) if %op eq 1 then setText %wso = Received your text message of {%wsi:length} bytes. %sock:SendWebSocket(%wso, %op, true) end if ...