netwerk/base/public/nsISocketTransportService.idlScriptable
This interface provides a mapping between a socket type and its associated socket provider instance. One could also use the service manager directly.
Inherits from: nsISupports Last changed in Gecko 1.9 (Firefox 3)

Implemented by: @mozilla.org/network/socket-transport-service;1. To create an instance, use:

var socketTransportService = Components.classes["@mozilla.org/network/socket-transport-service;1"]
                             .getService(Components.interfaces.nsISocketTransportService);

Method overview

void attachSocket(in PRFileDescPtr aFd, in nsASocketHandlerPtr aHandler); Native code only!
nsISocketTransport createTransport(in Array<ACString> aSocketTypes, in AUTF8String aHost, in long aPort, in nsIProxyInfo aProxyInfo);
void init(); Obsolete since Gecko 1.8
void notifyWhenCanAttachSocket(in nsIRunnable aEvent); Native code only!
void shutdown(); Obsolete since Gecko 1.8

Attributes

Attribute Type Description
autodialEnabled boolean controls whether or not the socket transport service should poke the autodialer on connection failure. Obsolete since Gecko 1.8

Methods

Native code only!

attachSocket

Adds a new socket to the list of controlled sockets.

This will fail with the error code NS_ERROR_NOT_AVAILABLE if the maximum number of sockets is already reached. In this case, the notifyWhenCanAttachSocket() method should be used.

Note: This function may only be called from an event dispatch on the socket thread.
void attachSocket(
  in PRFileDescPtr aFd,
  in nsASocketHandlerPtr aHandler
);
Parameters
aFd
Open file descriptor of the socket to control.
aHandler
Socket handler that will receive notifications when the socket is ready or detached.

createTransport()

Creates a transport for a specified host and port.

Note: This function can be called from any thread.
nsISocketTransport createTransport(
  in Array<ACString> aSocketTypes,
  in AUTF8String aHost,
  in long aPort,
  in nsIProxyInfo aProxyInfo
);
Parameters
aSocketTypes
Array of socket type strings. Currently "starttls", "ssl" and "udp" are supported. Pass an empty array [] if the default socket type should be used. You do not need to specify the strings "socks" or "socks4", use the aProxyInfo instead.
aHost
Specifies the target hostname or IP address literal of the peer for this socket.
aPort
Specifies the target port of the peer for this socket.
aProxyInfo
Specifies the transport-layer proxy type to use. Set to null if no proxy should be used.
For more details on communicating information about proxies like SOCKS (which are transparent to upper protocols), see nsIProxiedProtocolHandler , nsIProtocolProxyService or Proxies in Necko.
Return value

An nsISocketTransport containing the SocketTransport.

init()

Obsolete since Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0)
void init();
Parameters

None.

Native code only!

notifyWhenCanAttachSocket

If the number of sockets reaches the limit, then consumers can be notified when the number of sockets becomes less than the limit. The notification is asynchronous, delivered via the given nsIRunnable instance on the socket transport thread.

Note: This function may only be called from an event dispatch on the socket thread.
void notifyWhenCanAttachSocket(
  in nsIRunnable aEvent
);
Parameters
aEvent
Event that will receive the notification when a new socket can be attached.

shutdown()

Obsolete since Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0)
void shutdown();
Parameters

None.

Example

 // at first, we need a nsISocketTransportService ....
 var transportService =
     Components.classes["@mozilla.org/network/socket-transport-service;1"]
       .getService(Components.interfaces.nsISocketTransportService);

 // ... then it is time to create the transport. It will connect to ...
 // ... mozilla.org:2000 with TLS support and default proxy settings
 var socket = transportService.createTransport(["starttls"], 1,"mozilla.org", 2000, null);

See also