nsIDOMTCPSocket

Methods

open(host, port, options)

Create and return a socket object which will attempt to connect to
the given host and port.

   useSecureTransport: true to create an SSL socket. Defaults to false.  
  
   binaryType: "arraybuffer" to use ArrayBuffer  
     instances in the ondata callback and as the argument  
     to send. Defaults to "string", to use JavaScript strings.  

Parameters

host The hostname of the server to connect to.
port The port to connect to.
options An object specifying one or more parameters which determine the details of the socket.

Returns

The new TCPSocket instance.

listen(localPort, options, backlog)

Listen on a port

   binaryType: "arraybuffer" to use ArrayBuffer  
     instances in the ondata callback and as the argument  
     to send. Defaults to "string", to use JavaScript strings.  

Parameters

localPort The port of the server socket. Pass -1 to indicate no preference, and a port will be selected automatically.
options An object specifying one or more parameters which determine the details of the socket.
backlog The maximum length the queue of pending connections may grow to. This parameter may be silently limited by the operating system. Pass -1 to use the default value.

Returns

The new TCPServerSocket instance.

upgradeToSecure()

Enable secure on channel.

suspend()

Pause reading incoming data and invocations of the ondata handler until
resume is called.

resume()

Resume reading incoming data and invoking ondata as usual.

close()

Close the socket.

send(data, byteOffset, byteLength)

Write data to the socket.

Parameters

data The data to write to the socket. If binaryType: "arraybuffer" was passed in the options object, then this object should be an ArrayBuffer instance. If binaryType: "string" was passed, or if no binaryType option was specified, then this object should be an ordinary JavaScript string.
byteOffset The offset within the data from which to begin writing. Has no effect on non-ArrayBuffer data.
byteLength The number of bytes to write. Has no effect on non-ArrayBuffer data.

Returns

Send returns true or false 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 ondrain event handler has been called before buffering more data by more calls to send.

Attributes

host

The host of this socket object.

port

The port of this socket object.

ssl

True if this socket object is an SSL socket.

bufferedAmount

The number of bytes which have previously been buffered by calls to
send on this socket.

readyState

The readyState attribute indicates which state the socket is currently
in. The state will be either “connecting”, “open”, “closing”, or “closed”.

binaryType

The binaryType attribute indicates which mode this socket uses for
sending and receiving data. If the binaryType: “arraybuffer” option
was passed to the open method that created this socket, binaryType
will be “arraybuffer”. Otherwise, it will be “string”.

onopen

The onopen event handler is called when the connection to the server
has been established. If the connection is refused, onerror will be
called, instead.

ondrain

After send has buffered more than 64k of data, it returns false to
indicate that the client should pause before sending more data, to
avoid accumulating large buffers. This is only advisory, and the client
is free to ignore it and buffer as much data as desired, but if reducing
the size of buffers is important (especially for a streaming application)
ondrain will be called once the previously-buffered data has been written
to the network, at which point the client can resume calling send again.

ondata

The ondata handler will be called repeatedly and asynchronously after
onopen has been called, every time some data was available from the server
and was read. If binaryType: “arraybuffer” was passed to open, the data
attribute of the event object will be an ArrayBuffer. If not, it will be a
normal JavaScript string.

At any time, the client may choose to pause reading and receiving ondata
callbacks, by calling the socket’s suspend() method. Further invocations
of ondata will be paused until resume() is called.

onerror

The onerror handler will be called when there is an error. The data
attribute of the event passed to the onerror handler will have a
description of the kind of error.

If onerror is called before onopen, the error was connection refused,
and onclose will not be called. If onerror is called after onopen,
the connection was lost, and onclose will be called after onerror.

onclose

The onclose handler is called once the underlying network socket
has been closed, either by the server, or by the client calling
close.

If onerror was not called before onclose, then either side cleanly
closed the connection.