Home Contents | # websocket:send | Websocket | Core4 Lua Event System

## SYNOPSIS

1. websocket:send(opcode, message)
2. websocket:sendText(message)
3. websocket:sendBinary(message)
4. websocket:sendPing(message)
5. websocket:sendClose([status, reason])

## DESCRIPTION

These are a group of functions to send a message to the peer.

The most basic is websocket:send(). The opcode and the message contents can be freely specified.

The functions websocket:sendText(), websocket:sendBinary() and websocket:sendPing() are simple shortcuts of the previous function. The opcode is preset to 1, 2 and 9, respectively, as per RFC6455.

To inform the peer that the websocket communication is to end, call websocket:sendClose(). The optional parameters allow setting a specific close status code and reason string. By default, the status code is 1000 (normal close) and the reason is set to the string "Connection closed". After sending a close, no other messages are allowed to be sent to this socket.

## RETURN VALUE

All send functions return a boolean true/false to indicate success.

In case of an error, the error can be retrieved using websocket:lastError().

## SEE ALSO

websocket:detach(), websocket:attachServer(), websocket:attachClient()