SendWebSocket (Socket function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 6: Line 6:
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%number</th><td>Always returns zero. Any error will cause request cancellation.</td></tr>
<tr><th>socket</th>
<tr><th>socket</th>
<td>Socket object</td></tr>
<td>Socket object</td></tr>
Line 39: Line 38:
==Usage notes==
==Usage notes==
==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 16:21, 19 August 2019

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.
0 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.
1 A text frame. Text frames are are translated to ASCII with the translate table in effect for the port.
2 A binary frame. No translation is done for binary frames.
3-7 Reserved for future use and will cause request cancellation.
8 Connection close frame.
9 Ping. The receiver should respond with a Pong frame, unless a close frame has been received.
10 Pong. This is sent as a response to a Ping frame.
11-15 Reserved for future use and will cause request cancellation.
128 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.
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.

Usage notes

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 ...

See also