nsIUDPSocket

nsIUDPSocket

An interface to a UDP socket that can accept incoming connections.

Methods

init(aPort, aLoopbackOnly, aAddressReuse)

init

This method initializes a UDP socket.

Parameters

aPort The port of the UDP socket. Pass -1 to indicate no preference, and a port will be selected automatically.
aLoopbackOnly If true, the UDP socket will only respond to connections on the local loopback interface. Otherwise, it will accept connections from any interface. To specify a particular network interface, use initWithAddress.
aAddressReuse If true, the socket is allowed to be bound to an address that is already in use. Default is true.

initWithAddress(aAddr, aAddressReuse)

initWithAddress

This method initializes a UDP socket, and binds it to a particular
local address (and hence a particular local network interface).

Parameters

aAddr The address to which this UDP socket should be bound.
aAddressReuse If true, the socket is allowed to be bound to an address that is already in use. Default is true.

close()

close

This method closes a UDP socket. This does not affect already
connected client sockets (i.e., the nsISocketTransport instances
created from this UDP socket). This will cause the onStopListening
event to asynchronously fire with a status of NS_BINDING_ABORTED.

asyncListen(aListener)

asyncListen

This method puts the UDP socket in the listening state. It will
asynchronously listen for and accept client connections. The listener
will be notified once for each client connection that is accepted. The
listener’s onSocketAccepted method will be called on the same thread
that called asyncListen (the calling thread must have a nsIEventTarget).

The listener will be passed a reference to an already connected socket
transport (nsISocketTransport). See below for more details.

Parameters

aListener The listener to be notified when client connections are accepted.

getAddress()

Returns the address to which this UDP socket is bound. Since a
UDP socket may be bound to multiple network devices, this address
may not necessarily be specific to a single network device. In the
case of an IP socket, the IP address field would be zerod out to
indicate a UDP socket bound to all network devices. Therefore,
this method cannot be used to determine the IP address of the local
system. See nsIDNSService::myHostName if this is what you need.

send(host, port, data, dataLength)

send

Send out the datagram to specified remote host and port.
DNS lookup will be triggered.

Parameters

host The remote host name.
port The remote port.
data The buffer containing the data to be written.
dataLength The maximum number of bytes to be written.

Returns

number of bytes written. (0 or dataLength)

sendWithAddr(addr, data, dataLength)

sendWithAddr

Send out the datagram to specified remote host and port.

Parameters

addr The remote host address.
data The buffer containing the data to be written.
dataLength The maximum number of bytes to be written.

Returns

number of bytes written. (0 or dataLength)

sendWithAddress(addr, data, dataLength)

sendWithAddress

Send out the datagram to specified remote address and port.

Parameters

addr The remote host address.
data The buffer containing the data to be written.
dataLength The maximum number of bytes to be written.

Returns

number of bytes written. (0 or dataLength)

sendBinaryStream(host, port, stream)

sendBinaryStream

Send out the datagram to specified remote address and port.

Parameters

host The remote host name.
port The remote port.
stream The input stream to be sent. This must be a buffered stream implementation.

sendBinaryStreamWithAddress(addr, stream)

sendBinaryStreamWithAddress

Send out the datagram to specified remote address and port.

Parameters

addr The remote host address.
stream The input stream to be sent. This must be a buffered stream implementation.

joinMulticast(addr, iface)

joinMulticast

Join the multicast group specified by |addr|. You are then able to
receive future datagrams addressed to the group.

Parameters

addr The multicast group address.
iface The local address of the interface on which to join the group. If this is not specified, the OS may join the group on all interfaces or only the primary interface.

joinMulticastAddr(addr, iface)

leaveMulticast(addr, iface)

leaveMulticast

Leave the multicast group specified by |addr|. You will no longer
receive future datagrams addressed to the group.

Parameters

addr The multicast group address.
iface The local address of the interface on which to leave the group. If this is not specified, the OS may leave the group on all interfaces or only the primary interface.

leaveMulticastAddr(addr, iface)

Attributes

localAddr

Returns the local address of this UDP socket

port

Returns the port of this UDP socket.

multicastLoopback

multicastLoopback

Whether multicast datagrams sent via this socket should be looped back to
this host (assuming this host has joined the relevant group). Defaults
to true.
Note: This is currently write-only.

multicastInterface

multicastInterface

The interface that should be used for sending future multicast datagrams.
Note: This is currently write-only.

multicastInterfaceAddr

multicastInterfaceAddr

The interface that should be used for sending future multicast datagrams.
Note: This is currently write-only.