This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

send

Summary

Transmits data to the server over the WebSocket connection.

Method of apis/websocket/WebSocketapis/websocket/WebSocket

Syntax

 object.send(data);

Parameters

data

Data-type
any

Must be of one of the following types:

  • String
  • Blob
  • ArrayBuffer
  • ArrayBufferView

Return Value

No return value

Examples

var data = new ArrayBuffer(10000000);

// perform some operations on the ArrayBuffer
socket.send(data);

if (socket.bufferedAmount === 0) {
  // the data sent
}
else {
  // the data did not send
}

Notes

An ArrayBuffer is a unformatted block of raw data that is sent in its entirety to a server. An ArrayBufferView is a typed array view of an ArrayBuffer. By using a typed array to define the format of the buffer, and the start and length (number of elements), you can send portions of an ArrayBuffer to a server. This method can throw one of the following exceptions:

ExceptionDescription
InvalidStateError(11)The connection is not currently OPEN.

Related specifications

W3C WebSocket Specification
W3C Candidate Recommendation

Attributions