SendWebSocket (Socket function): Difference between revisions
m (→Usage notes) |
|||
(7 intermediate revisions by the same user not shown) | |||
Line 6: | Line 6: | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>socket</th> | <tr><th>socket</th> | ||
<td>Socket object</td></tr> | <td>Socket object</td></tr> | ||
Line 15: | Line 14: | ||
<table> | <table> | ||
<tr><th>0</th> | <tr><th>0</th> | ||
<td>A continuation frame. A continuation frame is treated as text or binary based on the op code of the first frame.</td></tr> | <td>A continuation frame. A continuation frame is treated as text or binary based on the op code of the first frame. A continuation frame cannot also be the first frame.</td></tr> | ||
<tr><th>1</th> | <tr><th>1</th> | ||
<td>A text frame. Text frames are are translated to ASCII with the translate table in effect for the port.</td></tr> | <td>A text frame. Text frames are are translated to ASCII with the translate table in effect for the port.</td></tr> | ||
Line 21: | Line 20: | ||
<td>A binary frame. No translation is done for binary frames.</td></tr> | <td>A binary frame. No translation is done for binary frames.</td></tr> | ||
<tr><th>3-7</th> | <tr><th>3-7</th> | ||
<td>Reserved for future use.</td></tr> | <td>Reserved for future use and will cause request cancellation.</td></tr> | ||
<tr><th>8</th> | <tr><th>8</th> | ||
<td>Connection close frame.</td></tr> | <td>Connection close frame.</td></tr> | ||
Line 29: | Line 28: | ||
<td>Pong. This is sent as a response to a Ping frame.</td></tr> | <td>Pong. This is sent as a response to a Ping frame.</td></tr> | ||
<tr><th>11-15</th> | <tr><th>11-15</th> | ||
<td>Reserved for future use.</td></tr> | <td>Reserved for future use and will cause request cancellation.</td></tr> | ||
<tr><th>128</th> | <tr><th>128</th> | ||
<td>This value is added to the frame op code to indicate the final fragment of a non-control message. The first fragment may also be the final fragment.</td></tr> | <td>This value is added to the frame op code to indicate the final fragment of a non-control message. The first fragment may also be the final fragment.</td></tr> | ||
Line 37: | 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 sends a text message to the WebSocket client. | |||
<p class="code">... | |||
%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 | |||
... | |||
</p> | |||
==See also== | ==See also== | ||
{{Template:Socket:SendWebSocket footer}} | {{Template:Socket:SendWebSocket footer}} |
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 ...