Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

CURL.WebSocketSend

Send the specific message fragment over an established WebSocket connection.

Component Version macOS Windows Linux Server iOS SDK
CURL 13.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "CURL.WebSocketSend"; curl; Text { ; Encoding; FrameSize; SendFlags } )   More

Parameters

Parameter Description Example Flags
curl The CURL session handle. $curl
Text The post data. ""
Encoding The text encoding for text parameter.
Default is UTF-8.
"UTF8" Optional
FrameSize The frame size.
Default is zero.
0 Optional
SendFlags The send flags.
Default is zero.
0 Optional

Result

Returns number or error.

Description

Send the specific message fragment over an established WebSocket connection.
The text parameter holds the data to send.

Returns the number of payload bytes actually sent.

To send a (huge) fragment using multiple calls with partial content per invoke, set the offset flag (32) in the flags and the FrameSize argument as the total expected size for the first part, then set the offset flag (32) with a zero FrameSize for the following parts.

If not sending a partial fragment or if this is raw mode, FrameSize should be set to zero.

If kWebSocketRaw is enabled in WebSocketOptions, the flags argument should be set to 0.

Examples

Test web socket:

# Start new session
Set Variable [ $curl ; Value: MBS("CURL.New") ]
# put in your web service test URL:
Set Variable [ $result ; Value: MBS("CURL.SetOptionURL"; $curl; "ws://yourserver.com/echo“) ]
# connect only with short timeout
Set Variable [ $result ; Value: MBS("CURL.SetOptionConnectionTimeout"; $curl; 5) ]
Set Variable [ $result ; Value: MBS("CURL.SetOptionConnectOnly"; $curl; 2) ]
# Do connection setup
Set Variable [ $result ; Value: MBS("CURL.Perform"; $curl) ]
Set Field [ CURL Test::Result ; $result ]
# Check result
Set Field [ CURL Test::Text ; MBS("CURL.GetResultAsText"; $curl; "UTF8") ]
Set Field [ CURL Test::debug ; MBS("CURL.GetDebugMessages"; $curl) ]
If [ $result = "OK" ]
    # send something
    Set Variable [ $result ; Value: MBS("CURL.WebSocketSend"; $curl; "Hello World") ]
    # receive answer
    Set Field [ CURL Test::header ; MBS("CURL.WebSocketReceive"; $curl) ]
End If
# Cleanup
Set Variable [ $result ; Value: MBS("CURL.Release"; $curl) ]

See also

Release notes

Blog Entries

This function checks for a license.

Created 11st December 2022, last changed 3th January 2023


CURL.WebSocketReceive - Calendar.Alarm.Duplicate