WebSocket Unicode C Reference Documentation

WebSocket

Current Version: 11.5.0

Chilkat.WebSocket

Connect to WebSocket servers and exchange client-side frames and messages.

Client-side only: Chilkat.WebSocket implements the client side of the WebSocket protocol. It initiates an opening handshake with an existing WebSocket server. It does not listen for incoming connections, accept clients, or implement a WebSocket server.

Chilkat.WebSocket operates over an established Chilkat.Rest connection. It creates and validates the HTTP upgrade handshake, sends and receives text or binary frames, supports fragmented messages, handles Ping, Pong, and Close control frames, polls for incoming data, and exposes frame-level diagnostics.

Client opening handshake

Upgrade a connected Rest session to WebSocket and validate the server's response before exchanging frames.

Text and binary messages

Send UTF-8 text or exact binary bytes as single-frame or fragmented WebSocket messages.

Frame-by-frame receiving

Read frames, inspect opcodes and the FIN state, and accumulate fragments until a complete message is available.

Ping and Pong

Use automatic or manual control-frame handling for keep-alive and responsiveness checks.

Clean close handshake

Exchange Close frames, inspect the peer's status code and reason, and terminate the underlying connection cleanly.

Separate read/write paths

Share a connection between two WebSocket objects when one thread needs to read while another writes.

Typical connection sequence: Connect a Rest object to the server, call UseConnection, call AddClientHeaders, send the opening HTTP GET request through Rest, and then call ValidateServerHandshake. Only after validation succeeds should the application call frame send/receive methods.
Frames versus messages: A WebSocket message may consist of one frame or several fragments. When receiving a fragmented message, call ReadFrame until FinalFrame is TRUE, then retrieve the accumulated data with GetFrameData, GetFrameDataSb, or GetFrameDataBd.

Create/Dispose

HCkWebSocketW instance = CkWebSocketW_Create();
// ...
CkWebSocketW_Dispose(instance);
HCkWebSocketW CkWebSocketW_Create(void);

Creates an instance of the HCkWebSocketW object and returns a handle ("void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.

void CkWebSocketW_Dispose(HCkWebSocketW handle);

Objects created by calling CkWebSocketW_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkWebSocketW_Dispose.

Callback Functions

Callback Functions introduced in Chilkat v9.5.0.56
void CkWebSocketW_setAbortCheck(HCkWebSocketW cHandle, BOOL (*fnAbortCheck)(void));

Provides the opportunity for a method call to be aborted. If TRUE is returned, the operation in progress is aborted. Return FALSE to allow the current method call to continue. This callback function is called periodically based on the value of the HeartbeatMs property. (If HeartbeatMs is 0, then no callbacks are made.) As an example, to make 5 AbortCheck callbacks per second, set the HeartbeatMs property equal to 200.

void CkWebSocketW_setPercentDone(HCkWebSocketW cHandle, BOOL (*fnPercentDone)(int pctDone));

Provides the percentage completed for any method that involves network communications or time-consuming processing (assuming it is a method where a percentage completion can be measured). This callback is only called when it is possible to know a percentage completion, and when it makes sense to express the operation as a percentage completed. The pctDone argument will have a value from 1 to 100. For methods that complete very quickly, the number of PercentDone callbacks will vary, but the final callback should have a value of 100. For long running operations, no more than one callback per percentage point will occur (for example: 1, 2, 3, ... 98, 99, 100).

This callback counts as an AbortCheck callback, and takes the place of the AbortCheck event when it fires.

The return value indicates whether the method call should be aborted, or whether it should proceed. Return TRUE to abort, and FALSE to proceed.

void CkWebSocketW_setProgressInfo(HCkWebSocketW cHandle, void (*fnProgressInfo)(const wchar_t *name, const wchar_t *value));

This is a general callback that provides name/value information about what is happening at certain points during a method call. To see the information provided in ProgressInfo callbacks, if any, write code to handle this event and log the name/value pairs. Most are self-explanatory.

void CkWebSocketW_setTaskCompleted(HCkWebSocketW cHandle, void (*fnTaskCompleted)(HCkTaskW hTask));

Called in the background thread when an asynchronous task completes. (Note: When an async method is running, all callbacks are in the background thread.)

Properties

CloseAutoRespond
BOOL CkWebSocketW_getCloseAutoRespond(HCkWebSocketW cHandle);
void CkWebSocketW_putCloseAutoRespond(HCkWebSocketW cHandle, BOOL newVal);
Introduced in version 9.5.0.70

Controls whether Chilkat automatically answers an incoming Close control frame.

  • When TRUE, an incoming Close is answered automatically if the client did not already initiate the close. After a Close has been both received and sent, Chilkat closes the underlying connection.
  • When FALSE, the application can detect the received Close through CloseReceived or FrameOpcode and call SendClose itself.

The default is TRUE.

Closing handshake: A peer that receives a Close and has not already sent one should respond with a Close. Automatic response is usually the safest choice unless the application must control the exact status code or timing.

top
CloseReason
void CkWebSocketW_getCloseReason(HCkWebSocketW cHandle, HCkString retval);
const wchar_t *CkWebSocketW_closeReason(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Returns the UTF-8 reason text contained in the received Close control frame.

The value is empty when the peer supplied no reason or when no Close frame has been received. A reason is diagnostic text and should not be treated as a stable machine-readable error identifier; use CloseStatusCode for protocol-level handling.

top
CloseReceived
BOOL CkWebSocketW_getCloseReceived(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

TRUE after a Close control frame has been received on the current WebSocket connection.

When CloseAutoRespond is FALSE, use this property to determine whether the application needs to call SendClose to complete the closing handshake. The received status code and reason, if present, are available through CloseStatusCode and CloseReason.

top
CloseStatusCode
int CkWebSocketW_getCloseStatusCode(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Returns the status code contained in the received Close control frame.

Returns 0 when no Close frame has been received or when the received Close frame did not include a status code.

Meaning of zero: 0 is an API sentinel; it is not a WebSocket close status transmitted by the peer.

top
DebugLogFilePath
void CkWebSocketW_getDebugLogFilePath(HCkWebSocketW cHandle, HCkString retval);
void CkWebSocketW_putDebugLogFilePath(HCkWebSocketW cHandle, const wchar_t *newVal);
const wchar_t *CkWebSocketW_debugLogFilePath(HCkWebSocketW cHandle);

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
FinalFrame
BOOL CkWebSocketW_getFinalFrame(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

TRUE if the frame most recently delivered by ReadFrame had its WebSocket FIN bit set; otherwise FALSE.

For a fragmented data message, continue reading while this property is FALSE. The fragment with TRUE completes the message. Unfragmented messages have TRUE on their only frame.

Control frames: Close, Ping, and Pong are control frames and are not fragmented by the WebSocket protocol; their FIN bit is always set.

top
FrameDataLen
int CkWebSocketW_getFrameDataLen(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Returns the number of payload bytes currently accumulated in the internal receive buffer.

The value can represent data from one frame or from multiple calls to ReadFrame, which is useful when receiving a fragmented message. The accumulated bytes remain available until retrieved by GetFrameData, GetFrameDataSb, or GetFrameDataBd.

Message length: This is the length accumulated so far, not necessarily the final length of the complete WebSocket message. Check FinalFrame to determine whether the last received fragment completed the message.

top
FrameOpcode
void CkWebSocketW_getFrameOpcode(HCkWebSocketW cHandle, HCkString retval);
const wchar_t *CkWebSocketW_frameOpcode(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Returns the symbolic opcode of the frame most recently delivered by ReadFrame.

ValueMeaning
ContinuationA later fragment of a Text or Binary message
TextUTF-8 text data
BinaryBinary data
CloseClosing handshake
PingPing control frame
PongPong control frame

Before any frame has been received, the value is the empty string. Ping or Pong frames handled internally by the auto-response/auto-consume options may not be returned as the current frame.

top
FrameOpcodeInt
int CkWebSocketW_getFrameOpcodeInt(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Returns the numeric opcode of the frame most recently delivered by ReadFrame.

ValueFrame type
0Continuation
1Text
2Binary
8Close
9Ping
10Pong

Use FrameOpcode when a readable symbolic value is preferred.

top
HeartbeatMs
int CkWebSocketW_getHeartbeatMs(HCkWebSocketW cHandle);
void CkWebSocketW_putHeartbeatMs(HCkWebSocketW cHandle, int newVal);
Introduced in version 9.5.0.97

Specifies the interval, in milliseconds, between AbortCheck event callbacks during supported blocking operations.

The default is 0, which disables periodic AbortCheck callbacks. Set a positive value when the application needs an opportunity to cancel a long-running send or receive operation.

Not a WebSocket heartbeat: Despite the property name, this setting does not transmit Ping frames and does not monitor peer liveness. Use SendPing and Ping/Pong handling for protocol-level heartbeat behavior.

More Information and Examples
top
IdleTimeoutMs
int CkWebSocketW_getIdleTimeoutMs(HCkWebSocketW cHandle);
void CkWebSocketW_putIdleTimeoutMs(HCkWebSocketW cHandle, int newVal);

Specifies the maximum number of milliseconds an active send or receive operation may remain stalled while waiting for additional network progress.

The default is 30000 milliseconds (30 seconds). This is an inactivity timeout, not a total limit on the duration of the operation. An operation may continue longer than this value as long as data continues to be transferred.

Not a keep-alive interval: This property does not automatically send WebSocket Ping frames. Use SendPing when the application needs protocol-level keep-alive or responsiveness checks.

top
IsConnected
BOOL CkWebSocketW_getIsConnected(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

TRUE when the underlying WebSocket network connection is currently open; otherwise FALSE.

Connection state is not a health check: A network interruption may not be detected until the next read or write operation. Use normal I/O results—and optionally Ping/Pong—to determine whether a seemingly connected peer is still responsive.

top
LastErrorHtml
void CkWebSocketW_getLastErrorHtml(HCkWebSocketW cHandle, HCkString retval);
const wchar_t *CkWebSocketW_lastErrorHtml(HCkWebSocketW cHandle);

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
void CkWebSocketW_getLastErrorText(HCkWebSocketW cHandle, HCkString retval);
const wchar_t *CkWebSocketW_lastErrorText(HCkWebSocketW cHandle);

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
void CkWebSocketW_getLastErrorXml(HCkWebSocketW cHandle, HCkString retval);
const wchar_t *CkWebSocketW_lastErrorXml(HCkWebSocketW cHandle);

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
BOOL CkWebSocketW_getLastMethodSuccess(HCkWebSocketW cHandle);
void CkWebSocketW_putLastMethodSuccess(HCkWebSocketW cHandle, BOOL newVal);

Indicates the success or failure of the most recent method call: TRUE means success, FALSE means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
NeedSendPong
BOOL CkWebSocketW_getNeedSendPong(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

TRUE when a Ping frame has been received but no corresponding Pong has yet been sent.

This property is primarily useful when PingAutoRespond is FALSE. Call SendPong as soon as practical; it automatically sends the received Ping payload in the Pong response.

top
PingAutoRespond
BOOL CkWebSocketW_getPingAutoRespond(HCkWebSocketW cHandle);
void CkWebSocketW_putPingAutoRespond(HCkWebSocketW cHandle, BOOL newVal);
Introduced in version 9.5.0.70

Controls automatic handling of incoming Ping control frames.

  • When TRUE, Chilkat sends the required Pong automatically and ReadFrame consumes the Ping internally, continuing until another frame is available.
  • When FALSE, the Ping can be returned to the application. Check NeedSendPong and call SendPong as soon as practical.

The default is TRUE.

Payload echo: A Pong sent in response to a Ping must carry the same application data. SendPong automatically uses the stored payload of the unanswered Ping.

top
PongAutoConsume
BOOL CkWebSocketW_getPongAutoConsume(HCkWebSocketW cHandle);
void CkWebSocketW_putPongAutoConsume(HCkWebSocketW cHandle, BOOL newVal);
Introduced in version 9.5.0.70

Controls whether incoming Pong control frames are hidden from the application.

  • When TRUE, ReadFrame consumes Pong frames internally and continues reading until a non-Pong frame is available.
  • When FALSE, an incoming Pong can be returned normally with FrameOpcode equal to Pong.

The default is TRUE. Check PongConsumed after ReadFrame to learn whether one or more Pong frames were consumed during that call.

top
PongConsumed
BOOL CkWebSocketW_getPongConsumed(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

TRUE if the most recent call to ReadFrame internally consumed a Pong frame while PongAutoConsume was TRUE.

The property is reset to FALSE at the beginning of each ReadFrame call and set to TRUE if a Pong is consumed during that call.

Why unsolicited Pong is possible: Either endpoint may send a Pong without a preceding Ping, and a response to an earlier Ping may arrive between application data frames. Automatic consumption allows ordinary read loops to ignore these control frames while still detecting that they occurred.

top
ReadFrameFailReason
int CkWebSocketW_getReadFrameFailReason(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

When ReadFrame returns FALSE, this property categorizes the reason:

ValueMeaning
0No failure is recorded
1Read inactivity timeout
2Aborted by an application callback
3Fatal socket error or lost connection
4Invalid WebSocket frame bytes were received
99Unexpected catch-all failure

Use this value for programmatic branching and inspect LastErrorText for detailed diagnostics.

top
UncommonOptions
void CkWebSocketW_getUncommonOptions(HCkWebSocketW cHandle, HCkString retval);
const wchar_t *CkWebSocketW_uncommonOptions(HCkWebSocketW cHandle);
Introduced in version 9.5.0.80

Contains a comma-separated list of rarely needed compatibility or platform options. The default is the empty string and should normally remain unchanged.

KeywordEffect
ProtectFromVpnOn Android, attempts to route the connection outside an installed or active VPN. Introduced in v9.5.0.80.
Platform-specific behavior: This option applies only on Android. Leave the property empty on other platforms and unless bypassing the device VPN is an explicit application requirement.

top
VerboseLogging
BOOL CkWebSocketW_getVerboseLogging(HCkWebSocketW cHandle);
void CkWebSocketW_putVerboseLogging(HCkWebSocketW cHandle, BOOL newVal);

If set to TRUE, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is FALSE. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
void CkWebSocketW_getVersion(HCkWebSocketW cHandle, HCkString retval);
const wchar_t *CkWebSocketW_version(HCkWebSocketW cHandle);

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

AddClientHeaders
BOOL CkWebSocketW_AddClientHeaders(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Adds the standard client opening-handshake headers to the Rest object supplied to UseConnection:

Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: ...
Sec-WebSocket-Version: 13

Sec-WebSocket-Key contains a newly generated client nonce used by the server to produce Sec-WebSocket-Accept.

Additional handshake headers: If the server requires headers such as Origin, Authorization, cookies, or Sec-WebSocket-Protocol, add them through the associated Rest object before sending the HTTP upgrade request.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
CloseConnection
BOOL CkWebSocketW_CloseConnection(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Immediately closes the underlying network connection without completing the WebSocket closing handshake.

Use this method when the connection must be abandoned because of a fatal error, timeout, application shutdown, or an unresponsive peer.

Preferred shutdown: For a normal shutdown, call SendClose, receive the peer's Close frame with ReadFrame, and allow the closing handshake to complete. An abrupt transport close does not provide the peer with a WebSocket status code or reason.

Returns TRUE for success, FALSE for failure.

top
GetFrameData
BOOL CkWebSocketW_GetFrameData(HCkWebSocketW cHandle, const wchar_t *outStr);
const wchar_t *CkWebSocketW_getFrameData(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Returns the bytes accumulated by successful calls to ReadFrame as a string, then clears the internal receive buffer.

This method is intended for WebSocket text-message data. For arbitrary binary payloads, use GetFrameDataBd to avoid interpreting binary bytes as text.

Fragmented messages: To retrieve an entire fragmented message, continue calling ReadFrame until FinalFrame is TRUE, and then call GetFrameData once. Calling this method earlier returns and clears only the data accumulated so far.

Returns TRUE for success, FALSE for failure.

top
GetFrameDataBd
BOOL CkWebSocketW_GetFrameDataBd(HCkWebSocketW cHandle, HCkBinDataW binData);
Introduced in version 9.5.0.70

Appends the bytes accumulated by successful calls to ReadFrame to binData, then clears the internal receive buffer.

Use this method for binary messages or whenever the exact received bytes must be preserved. Existing data in the destination BinData is retained because the received bytes are appended.

Receive-buffer ownership: Calling any one of GetFrameData, GetFrameDataSb, or GetFrameDataBd consumes the same internal buffer. Retrieve the data using only the form needed by the application.
More Information and Examples
top
GetFrameDataSb
BOOL CkWebSocketW_GetFrameDataSb(HCkWebSocketW cHandle, HCkStringBuilderW sb);
Introduced in version 9.5.0.70

Appends the text represented by the bytes accumulated by successful calls to ReadFrame to sb, then clears the internal receive buffer.

Existing text in the destination StringBuilder is retained. This method is most appropriate for text-message data; use GetFrameDataBd for arbitrary binary payloads.

Fragmented messages: The receive buffer can accumulate multiple frames. Read until FinalFrame is TRUE before calling this method when the application wants the complete message.
top
LoadTaskCaller
BOOL CkWebSocketW_LoadTaskCaller(HCkWebSocketW cHandle, HCkTaskW task);
Introduced in version 9.5.0.80

Loads the caller object associated with an asynchronous Task method invocation.

This is used by Chilkat's asynchronous task infrastructure when access to the original WebSocket object is required after the task completes.

Returns TRUE for success, FALSE for failure.

top
PollDataAvailable
BOOL CkWebSocketW_PollDataAvailable(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Checks whether bytes are currently waiting to be read from the underlying WebSocket connection.

Returns TRUE when incoming data is available and FALSE when no data is presently waiting.

Polling is only a snapshot: A TRUE result does not mean that an entire WebSocket frame or message has arrived. Call ReadFrame to parse the protocol frame. A FALSE result does not indicate that the peer will not send data later.
top
ReadFrame
BOOL CkWebSocketW_ReadFrame(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Reads the next WebSocket frame from the connected server. On success, the method updates FrameOpcode, FrameOpcodeInt, FinalFrame, and FrameDataLen.

Frame payload bytes are added to an internal receive buffer. The buffer may therefore contain data accumulated by multiple calls to ReadFrame. Retrieve and clear it with GetFrameData, GetFrameDataSb, or GetFrameDataBd.

Reading a complete message

Call ReadFrame until FinalFrame is TRUE, then retrieve the accumulated message data. A fragmented message begins with a Text or Binary frame and continues with one or more Continuation frames.

Control-frame automation: Depending on PingAutoRespond and PongAutoConsume, incoming Ping and Pong frames may be handled internally, causing this method to continue reading until another frame is available. If the method returns FALSE, inspect ReadFrameFailReason and LastErrorText.

Returns TRUE for success, FALSE for failure.

top
ReadFrameAsync (1)
HCkTaskW CkWebSocketW_ReadFrameAsync(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Creates an asynchronous task to call the ReadFrame method with the arguments provided.

Returns NULL on failure

top
SendClose
BOOL CkWebSocketW_SendClose(HCkWebSocketW cHandle, BOOL includeStatus, int statusCode, const wchar_t *reason);
Introduced in version 9.5.0.70

Sends a WebSocket Close control frame and begins or completes the closing handshake.

  • If includeStatus is FALSE, the Close frame contains no status code and statusCode and reason are ignored.
  • If includeStatus is TRUE, the frame contains statusCode followed by the UTF-8 bytes of reason.

The complete Close payload cannot exceed 125 bytes, leaving at most 123 bytes for the UTF-8 reason after the two-byte status code. Chilkat truncates an overlong reason. The API accepts status-code integers from 0 through 16383.

Protocol-valid status codes: The API's numeric range is broader than the set valid for transmission under RFC 6455. Use a defined protocol code such as 1000 for normal closure, or an appropriate application code in the 30004999 range. Codes 1005, 1006, and 1015 are reserved reporting values and must not be sent in a Close frame.
Clean close: After initiating a close, read the peer's Close response. If this method answers a Close already received from the server, Chilkat also closes the underlying connection after sending the response.

Returns TRUE for success, FALSE for failure.

top
SendCloseAsync (1)
HCkTaskW CkWebSocketW_SendCloseAsync(HCkWebSocketW cHandle, BOOL includeStatus, int statusCode, const wchar_t *reason);
Introduced in version 9.5.0.70

Creates an asynchronous task to call the SendClose method with the arguments provided.

Returns NULL on failure

top
SendFrame
BOOL CkWebSocketW_SendFrame(HCkWebSocketW cHandle, const wchar_t *stringToSend, BOOL finalFrame);
Introduced in version 9.5.0.70

Sends one WebSocket text data frame containing stringToSend. WebSocket text data is UTF-8 on the wire.

  • Set finalFrame to TRUE when this frame completes the message.
  • Set finalFrame to FALSE when additional frames will follow as part of the same fragmented message.

For a normal unfragmented text message, call this method once with finalFrame set to TRUE. For a fragmented message, call it repeatedly and set TRUE only for the final fragment.

Frames and messages: A WebSocket message may contain one frame or multiple fragments. Do not begin a second data message until the current fragmented message has been completed. Control frames such as Ping, Pong, and Close may occur between message fragments.

Returns TRUE for success, FALSE for failure.

top
SendFrameAsync (1)
HCkTaskW CkWebSocketW_SendFrameAsync(HCkWebSocketW cHandle, const wchar_t *stringToSend, BOOL finalFrame);
Introduced in version 9.5.0.70

Creates an asynchronous task to call the SendFrame method with the arguments provided.

Returns NULL on failure

top
SendFrameBd
BOOL CkWebSocketW_SendFrameBd(HCkWebSocketW cHandle, HCkBinDataW bdToSend, BOOL finalFrame);
Introduced in version 9.5.0.70

Sends one WebSocket binary data frame containing the current bytes in bdToSend.

  • Set finalFrame to TRUE when this frame completes the binary message.
  • Set finalFrame to FALSE when additional binary-message fragments will follow.

For an ordinary single-frame binary message, set finalFrame to TRUE.

Exact bytes: No text encoding is involved. The bytes stored in bdToSend become the frame payload, while Chilkat applies the client-side WebSocket framing and masking required by the protocol.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
SendFrameBdAsync (1)
HCkTaskW CkWebSocketW_SendFrameBdAsync(HCkWebSocketW cHandle, HCkBinDataW bdToSend, BOOL finalFrame);
Introduced in version 9.5.0.70

Creates an asynchronous task to call the SendFrameBd method with the arguments provided.

Returns NULL on failure

top
SendFrameSb
BOOL CkWebSocketW_SendFrameSb(HCkWebSocketW cHandle, HCkStringBuilderW sbToSend, BOOL finalFrame);
Introduced in version 9.5.0.70

Sends one WebSocket text data frame containing the current contents of sbToSend.

  • Set finalFrame to TRUE when this frame completes the message.
  • Set finalFrame to FALSE when more fragments will follow.

For an ordinary single-frame text message, set finalFrame to TRUE. WebSocket text data is UTF-8 on the wire.

Message fragmentation: Repeated calls with finalFrame set to FALSE create fragments of the same text message. Complete the message with a final call that passes TRUE.

Returns TRUE for success, FALSE for failure.

top
SendFrameSbAsync (1)
HCkTaskW CkWebSocketW_SendFrameSbAsync(HCkWebSocketW cHandle, HCkStringBuilderW sbToSend, BOOL finalFrame);
Introduced in version 9.5.0.70

Creates an asynchronous task to call the SendFrameSb method with the arguments provided.

Returns NULL on failure

top
SendPing
BOOL CkWebSocketW_SendPing(HCkWebSocketW cHandle, const wchar_t *pingData);
Introduced in version 9.5.0.70

Sends a WebSocket Ping control frame. If pingData is non-empty, its UTF-8 bytes are included as the Ping payload.

WebSocket control-frame payloads are limited to 125 bytes. If the UTF-8 representation exceeds this limit, Chilkat truncates it to 125 bytes.

Ping/Pong behavior: A peer that receives a Ping is expected to send a Pong containing the same application data as soon as practical. Ping is useful for protocol-level liveness checks, but receiving a Pong does not by itself prove that the application running above the connection is healthy.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
SendPingAsync (1)
HCkTaskW CkWebSocketW_SendPingAsync(HCkWebSocketW cHandle, const wchar_t *pingData);
Introduced in version 9.5.0.70

Creates an asynchronous task to call the SendPing method with the arguments provided.

Returns NULL on failure

top
SendPong
BOOL CkWebSocketW_SendPong(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Sends a WebSocket Pong control frame.

When a Ping has been received and has not yet been answered, this method automatically uses the previously received Ping payload as the Pong payload, as required for a Ping response.

Manual response mode: This method is normally used when PingAutoRespond is FALSE and NeedSendPong is TRUE. When automatic Ping handling is enabled, Chilkat sends the Pong internally.

Returns TRUE for success, FALSE for failure.

top
SendPongAsync (1)
HCkTaskW CkWebSocketW_SendPongAsync(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Creates an asynchronous task to call the SendPong method with the arguments provided.

Returns NULL on failure

top
ShareConnection
BOOL CkWebSocketW_ShareConnection(HCkWebSocketW cHandle, HCkWebSocketW ws);
Introduced in version 11.0.0

Causes the calling WebSocket object to share the already-established WebSocket connection owned by ws.

This enables a bidirectional design in which separate WebSocket objects operate on the same connection—for example, one thread blocks in ReadFrame while another thread sends frames.

Concurrency model: Use this feature to separate the read path from the write path. The application remains responsible for coordinating object lifetime, shutdown, and higher-level message state. Avoid multiple concurrent readers or multiple unsynchronized writers unless the application provides its own coordination.

Returns TRUE for success, FALSE for failure.

top
UseConnection
BOOL CkWebSocketW_UseConnection(HCkWebSocketW cHandle, HCkRestW connection);
Introduced in version 9.5.0.70

Associates this WebSocket object with an existing, connected Rest object and prepares it for a client-side WebSocket session.

The opening WebSocket handshake is an HTTP GET upgrade request. Using Rest for the underlying connection allows the application to configure TLS, proxies, authentication, custom request headers, IPv6, socket options, bandwidth limits, and other connection features before the upgrade is performed.

Client-side API: Chilkat.WebSocket initiates connections to WebSocket servers. It does not listen for incoming connections or implement a WebSocket server endpoint.
Typical opening sequence
  1. Connect the Rest object to the server.
  2. Call UseConnection.
  3. Call AddClientHeaders.
  4. Send the HTTP GET request with the Rest object.
  5. Call ValidateServerHandshake.

Returns TRUE for success, FALSE for failure.

top
ValidateServerHandshake
BOOL CkWebSocketW_ValidateServerHandshake(HCkWebSocketW cHandle);
Introduced in version 9.5.0.70

Validates the server's response to the WebSocket opening handshake sent through the associated Rest object.

Validation checks that the server accepted the HTTP upgrade and returned the expected WebSocket handshake response, including the value derived from the client's Sec-WebSocket-Key. If this method returns TRUE, the connection has entered the WebSocket protocol and data or control frames may be exchanged.

Call order: Call this method only after the Rest object has sent the opening GET request and received the server's response. A successful HTTP request alone does not establish a WebSocket session; the response must also pass this validation.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top