mozilla
Your Search Results

    TCPSocket.send()

    Non-standard
    This feature is not on a current W3C standards track, but it is supported on the Firefox OS platform. Although implementations may change in the future and it is not supported widely across browsers, it is suitable for use in code dedicated to Firefox OS apps.

    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 the open() 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 the drain event has been triggered before buffering more data by more calls to send.

    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.

    See also

    Document Tags and Contributors

    Contributors to this page: kscarfone, teoli, Jeremie
    Last updated by: teoli,