ReceiveWebSocket (Socket function): Difference between revisions
(5 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%opCode</th> | <tr><th>%opCode</th> | ||
<td> | <td>op code is a number indicating the type of web socket frame received. Numbers 0-7 are non-control frames. Numbers 8-15 are control frames. | ||
<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.</td></tr> | ||
<tr><th>1</th> | <tr><th>1</th> | ||
<td>A text frame. Text frames are are translated to | <td>A text frame. Text frames are are translated to EBCDIC with the translate table in effect for the port.</td></tr> | ||
<tr><th>2</th> | <tr><th>2</th> | ||
<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> | ||
Line 18: | Line 18: | ||
<td>Reserved for future use.</td></tr> | <td>Reserved for future use.</td></tr> | ||
<tr><th>8</th> | <tr><th>8</th> | ||
<td>Connection close frame.</td></tr> | <td>Connection close frame. A close frame should be sent in response.</td></tr> | ||
<tr><th>9</th> | <tr><th>9</th> | ||
<td>Ping. The receiver should respond with a Pong frame, unless a close frame has been received.</td></tr> | <td>Ping. The receiver should respond with a Pong frame, unless a close frame has been received.</td></tr> | ||
Line 36: | Line 36: | ||
==Usage notes== | ==Usage notes== | ||
Received data may be masked by the sender. Masked data is always unmasked using the sender's masking key before it is returned to the application. | |||
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 receives a text message from a 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:ReceiveWebSocket footer}} | {{Template:Socket:ReceiveWebSocket footer}} |
Latest revision as of 16:27, 19 August 2019
Receive Web Socket framed message (Socket class)
[Introduced in Model 204 7.8 βeta]
This page is under construction.
Syntax
%opCode = socket:ReceiveWebSocket( string)
Syntax terms
%opCode | op code is a number indicating the type of web socket frame received. Numbers 0-7 are non-control frames. Numbers 8-15 are control frames.
| ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
socket | Socket object | ||||||||||||||||||
string | string |
Usage notes
Received data may be masked by the sender. Masked data is always unmasked using the sender's masking key before it is returned to the application.
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 receives a text message from a 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 ...