• Skip to main content
  • Select language
  • Skip to search
mozilla
Mozilla Developer Network
  • Sign in
    • Persona
    • GitHub
  • Web Platform
    Technologies
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • APIs / DOM
    • Apps
    • MathML
    References & Guides
    • Learn the Web
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • ...more docs
  • Mozilla Docs
    • Add-ons
    • Firefox
    • Firefox Marketplace
    • Firefox OS
    • Persona
  • Developer Tools
  • Feedback
    • Get Firefox help
    • Get web development help
    • Join the MDN community
    • Report a content problem
    • Report a bug
  •  
B2G OS
    • Français
    • 正體中文 (繁體)
    • Add a translation
  • Edit
  • Advanced
    • History
    • Print this article
  1. MDN
  2. Mozilla
  3. B2G OS
  4. Firefox OS APIs
  5. TCPSocket
Your Search Results

    TCPSocket

    In This Article
    1. Summary
    2. API overview
    3. Properties
      1. Events handler
    4. Methods
    5. Specification
    6. See also

    This API is available on Firefox OS for privileged or certified applications only.

    SummaryEdit

    The TCPSocket interface provides access to a raw TCP socket.

    The main entry point for this API is the navigator.mozTCPSocket property which is a TCPSocket object.

    Note: Only certified apps can accept incoming connections on a port below 1024.

    API overviewEdit

    interface TCPSocket{
      readonly attribute DOMString host;
      readonly attribute unsigned short port;
      readonly attribute boolean ssl;
      readonly attribute unsigned long bufferedAmount;
      readonly attribute DOMString binaryType;
      readonly attribute DOMString readyState;
    
      TCPSocket open(DOMString host, unsigned short port, [object options]);
      TCPServerSocket listen(unsigned short port, [object options, [unsigned short backlog]]);
      void upgradeToSecure();
      void suspend();
      void resume();
      void close();
      boolean send(in jsval data);
    
      attribute onopen;
      attribute ondrain;
      attribute ondata;
      attribute onerror;
      attribute onclose;
    };

    PropertiesEdit

    TCPSocket.host Read only
    A string representing the host name of the server the socket is connected to.
    TCPSocket.port Read only
    A number representing the port the socket is connected to.
    TCPSocket.ssl Read only
    A boolean indicating whether the socket is encrypted with SSL (true) or not (false).
    TCPSocket.bufferedAmount Read only
    The number of bytes of not-yet-sent data in the socket buffered.
    TCPSocket.binaryType Read only
    The type of data used. Possible value is arraybuffer or string.
    TCPSocket.readyState Read only
    The socket state. Possible value is connecting, open, closing, or closed.

    Events handler

    TCPSocket.onopen
    A handler for the open event. After this event, the socket is ready to send and receive data.
    TCPSocket.ondrain
    A handler for the drain event. This event is triggered each time the buffer of data is flushed.
    TCPSocket.onerror
    A handler for the error event.
    TCPSocket.ondata
    A handler for the data event. This event is triggered each time data has been received.
    TCPSocket.onclose
    A handler for the close event.

    MethodsEdit

    TCPSocket.close()
    Closes the connection.
    TCPSocket.open(host, port [, options])
    Returns a new TCPSocket object connected to the given host at the given port.
    TCPSocket.listen(port [, options [, backlog]]) Requires FirefoxOS 1.2
    Returns a new TCPServerSocket object listening at the given port.
    TCPSocket.resume()
    Resumes the data events.
    TCPSocket.send(data)
    Buffers data to be sent across the network.
    TCPSocket.suspend()
    Pauses the data events.
    TCPSocket.upgradeToSecure() Requires FirefoxOS 1.2
    Enables secure on channel.

    SpecificationEdit

    Not part of any specification yet; however, this API is discussed at W3C as part of the System Applications Working Group under the TCP and UDP Socket API (formerly known as the Raw Sockets API) proposal.

    See alsoEdit

    • TCP Socket
    Share:
    • Twitter
    • Facebook
    • Google+

    Document Tags and Contributors

    Tags: 
    • API
    • B2G
    • Firefox OS
    • Non-standard
    • Reference
    • Référence
    • TCP Socket
     Contributors to this page: chrisdavidmills, teoli, kscarfone, daftshady, Flaki, Sicking, Jeremie, donovanpreston, fabrice.desre, Sheppy, dbruant
     Last updated by: chrisdavidmills, Feb 11, 2016, 7:31:22 AM
    See also
    1. TCP Socket API
    2. TCPSocket
    3. Properties
      1. binaryType
      2. bufferedAmount
      3. host
      4. onclose
      5. ondata
      6. ondrain
      7. onerror
      8. onopen
      9. port
      10. readyState
      11. ssl
    4. Methods
      1. close()
      2. listen()
      3. open()
      4. resume()
      5. send()
      6. suspend()
      7. upgradeToSecure()
    5. Events
      1. data
      2. drain
      3. connect
      4. error
    6. Related pages for TCP Socket API
      1. Navigator.mozTCPSocket
      2. TCPServerSocket

    © 2005-2016 Mozilla Developer Network and individual contributors.

    Content is available under these licenses.

    • About MDN
    • Terms
    • Privacy
    • Cookies
    • Contribute to the code

    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy
    BESbswy