Interface nsIUDPSocketType

nsIUDPSocket

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

Hierarchy

Properties

dontFragment: boolean

dontFragment

The don't fragment flag. The socket must be initialized before calling this function.

localAddr: nsINetAddr

Returns the local address of this UDP socket

multicastInterface: string

multicastInterface

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

multicastInterfaceAddr: NetAddr

multicastInterfaceAddr

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

multicastLoopback: boolean

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.

port: number

Returns the port of this UDP socket.

recvBufferSize: number

recvBufferSize

The size of the receive buffer. Default depends on the OS.

sendBufferSize: number

sendBufferSize

The size of the send buffer. Default depends on the OS.

Methods

  • Increases the reference count for this interface. The associated instance will not be deleted unless the reference count is returned to zero.

    Returns

    The resulting reference count.

    Returns number

  • Parameters

    • aIID: object
    • Optional aInstancePtr: object

    Returns any

  • A run time mechanism for interface discovery.

    Returns

    NS_OK if the interface is supported by the associated instance, NS_NOINTERFACE if it is not.

    aInstancePtr must not be null.

    Parameters

    • aIID: object

      [in] A requested interface IID

    • aInstancePtr: object

      [out] A pointer to an interface pointer to receive the result.

    Returns void

  • Decreases the reference count for this interface. Generally, if the reference count returns to zero, the associated instance is deleted.

    Returns

    The resulting reference count.

    Returns number

  • 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: nsIUDPSocketListener

      The listener to be notified when client connections are accepted.

    Returns void

  • 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.

    Returns void

  • connect

    This method connects the UDP socket to a remote UDP address.

    Parameters

    • aAddr: NetAddrPtr

    Returns void

  • 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.

    Returns NetAddr

  • init

    This method initializes a UDP socket.

    Parameters

    • aPort: number

      The port of the UDP socket. Pass -1 to indicate no preference, and a port will be selected automatically.

    • aLoopbackOnly: boolean

      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.

    • aPrincipal: nsIPrincipal

      The principal connected to this socket.

    • aAddressReuse: boolean

      If true, the socket is allowed to be bound to an address that is already in use. Default is true.

    Returns void

  • Parameters

    • aAddr: string
    • aPort: number
    • aPrincipal: nsIPrincipal
    • aAddressReuse: boolean

    Returns void

  • initWithAddress

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

    Parameters

    • aAddr: NetAddrPtr

      The address to which this UDP socket should be bound.

    • aPrincipal: nsIPrincipal

      The principal connected to this socket.

    • aAddressReuse: boolean

      If true, the socket is allowed to be bound to an address that is already in use. Default is true.

    Returns void

  • joinMulticast

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

    Parameters

    • addr: string

      The multicast group address.

    • iface: string

      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.

    Returns void

  • Parameters

    • addr: NetAddr
    • iface: NetAddrPtr

    Returns void

  • leaveMulticast

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

    Parameters

    • addr: string

      The multicast group address.

    • iface: string

      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.

    Returns void

  • Parameters

    • addr: NetAddr
    • iface: NetAddrPtr

    Returns void

  • Receive a datagram.

    Parameters

    • addr: NetAddr

      The remote host address.

    • data: invalid

      The buffer to store received datagram.

    Returns void

  • send

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

    Returns

    number of bytes written. (0 or length of data)

    Parameters

    • host: string

      The remote host name.

    • port: number

      The remote port.

    • data: invalid

      The buffer containing the data to be written.

    Returns number

  • sendBinaryStream

    Send out the datagram to specified remote address and port.

    Parameters

    • host: string

      The remote host name.

    • port: number

      The remote port.

    • stream: nsIInputStream

      The input stream to be sent. This must be a buffered stream implementation.

    Returns void

  • sendBinaryStreamWithAddress

    Send out the datagram to specified remote address and port.

    Parameters

    • addr: NetAddrPtr

      The remote host address.

    • stream: nsIInputStream

      The input stream to be sent. This must be a buffered stream implementation.

    Returns void

  • sendWithAddr

    Send out the datagram to specified remote host and port.

    Returns

    number of bytes written. (0 or length of data)

    Parameters

    • addr: nsINetAddr

      The remote host address.

    • data: invalid

      The buffer containing the data to be written.

    Returns number

  • sendWithAddress

    Send out the datagram to specified remote address and port.

    Returns

    number of bytes written. (0 or length of data)

    Parameters

    • addr: NetAddrPtr

      The remote host address.

    • data: invalid

      The buffer containing the data to be written.

    Returns number

  • This adds a nsIUDPSocketSyncListener listener (defined below). When data is available onPacketReceived is called and the lisener uses recvWithAddr to actually retrive data from the socket. The listener can be use only if it runs on the socket thread. If it is used off the socket thread there is a risk of triggering a bug in OS thatcan cause a crash.

    Parameters

    • aListener: nsIUDPSocketSyncListener

    Returns void

Generated using TypeDoc