This API is available on Firefox OS for privileged or certified applications only.
Summary
The send
method is used to buffer data to be sent to the server.
Syntax
var theBufferIsFull = instanceOfTCPSocket.send(data[, byteOffset[, byteLength]]);
Parameters
data
- The data to write to the socket. Depending on the
binaryType
option passed to theopen()
method, it will be a string or an ArrayBuffer. byteOffset
- The offset within the data from which to begin writing. Only relevant for ArrayBuffer data.
byteLength
- The number of bytes to write. Only relevant for ArrayBuffer data.
Returns
It returns a boolean as a hint to the caller that they may either continue sending more data immediately, or may want to wait until the other side has read some of the data which has already been written to the socket before buffering more.
- If send returns
true
, then less than 64k has been buffered and it's safe to immediately write more. - If send returns
false
, then more than 64k has been buffered, and the caller may wish to wait until thedrain
event has been triggered before buffering more data by more calls tosend
.
Example
var socket = navigator.mozTCPSocket.open("www.mozilla.org", 80);
function pushData() {
var data;
// Do stuff that retrieves data
// Fill the buffer as much as you can
while(data != null && socket.send(data));
}
// Resume pushing data when the buffer is flushed
socket.ondrain = pushData;
// Start pushing data
pushData();
Specification
Not part of any specification yet; however, this API is discussed at W3C as part of the System Applications Working Group under the Raw Sockets proposal.