WebSocket:Send Asynchronous

Send a string to the server through an open WebSocket. Kawaii queues the message for transmission and returns without waiting for delivery.

Syntax
Luau
WebSocket:Send(message: string, binary: boolean?) -> ()

Parameters

Call this method with a WebSocket receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.

Function parameters
ParameterTypeDescription
messagestringText or binary message bytes, up to 16 MiB.
binaryboolean?true selects a binary message. Omitted, nil, or false selects a text message.

Returns

()

This function returns no values.

Usage notes

Sending through a closed socket or sending an oversized message raises an error. A successful return confirms queuing, not receipt by the server.

Differences from sUNC

The sUNC method accepts only a message string. Kawaii adds the optional binary argument.

Example

Example
Luau
-- Start an echo server you control on this device, or replace the URL.
local socket = WebSocket.connect("ws://127.0.0.1:8765")
local received = socket.OnMessage:Connect(function(message)
    print("Echo:", message)
end)
socket:Send("example message")
task.wait(2)
received:Disconnect()
socket:Close()
Kawaii documentation