files/en-us/web/api/websocket/send/index.md
{{APIRef("WebSockets API")}}{{AvailableInWorkers}}
The WebSocket.send() method enqueues the specified data
to be transmitted to the server over the WebSocket connection, increasing the value of
bufferedAmount by the number of bytes needed to contain the data. If the
data can't be sent (for example, because it needs to be buffered but the buffer is
full), the socket is closed automatically.
The browser will throw an exception if you call send() when the connection is in the CONNECTING state. If you call send() when the connection is in the CLOSING or CLOSED states, the browser will silently discard the data.
send(data)
data
string
bufferedAmount is increased by the number of bytes required to
represent the UTF-8 string.bufferedAmount by the requisite number of bytes.Blob enqueues the blob's raw data to be transmitted in
a binary frame (the {{domxref("Blob.type")}} is ignored).
The value of bufferedAmount is increased by the byte size of that raw data.bufferedAmount by the requisite number of bytes.None ({{jsxref("undefined")}}).
InvalidStateError {{domxref("DOMException")}}
CONNECTING.{{Specifications}}
{{Compat}}