Module jls.net.UdpSocket

Represents a UDP socket.

Class UdpSocket

udpSocket:bind (addr, port, options) Binds this socket to the specified address and port number.
udpSocket:setBroadcast (value) Enables or disables broadcast.
udpSocket:setLoopbackMode (value) Enables or disables multicast loopback mode.
udpSocket:setTimeToLive (value) Sets the multicast time to live value.
udpSocket:setInterface (ifaddr) Sets the multicast interface.
udpSocket:joinGroup (mcastaddr, ifaddr) Joins a group.
udpSocket:leaveGroup (mcastaddr, ifaddr) Leaves a group.
udpSocket:receiveStart (stream) Starts receiving datagram packets on this socket.
udpSocket:receiveStop () Stops receiving datagram packets on this socket.
udpSocket:send (data, addr, port[, callback]) Sends the specified datagram packet on this socket to the specified address and port number.
udpSocket:close ([callback]) Closes this socket.


Class UdpSocket

The UdpSocket class. An UDP socker allows to send and receive datagram packets.
udpSocket:bind (addr, port, options)
Binds this socket to the specified address and port number.

Parameters:

  • addr string the IP address.
  • port number the port number.
  • options table the options to set, available options are reuseaddr and ipv6only.

Usage:

    local s = UdpSocket:new()
    s:bind('0.0.0.0', 1900, {reuseaddr = true, ipv6only = false})
udpSocket:setBroadcast (value)
Enables or disables broadcast.

Parameters:

  • value boolean true to activate broadcast.
udpSocket:setLoopbackMode (value)
Enables or disables multicast loopback mode.

Parameters:

  • value boolean true to activate loopback mode.
udpSocket:setTimeToLive (value)
Sets the multicast time to live value.

Parameters:

  • value number the time to live.
udpSocket:setInterface (ifaddr)
Sets the multicast interface.

Parameters:

  • ifaddr string the multicast interface.
udpSocket:joinGroup (mcastaddr, ifaddr)
Joins a group.

Parameters:

  • mcastaddr string the multicast address.
  • ifaddr string the interface address.
udpSocket:leaveGroup (mcastaddr, ifaddr)
Leaves a group.

Parameters:

  • mcastaddr string the multicast address.
  • ifaddr string the interface address.
udpSocket:receiveStart (stream)
Starts receiving datagram packets on this socket.

Parameters:

  • stream the stream reader, could be a function or a StreamHandler.

Usage:

    local s = UdpSocket:new()
    s:receiveStart(function(err, data, addr)
      print('received', err, data)
    end)
udpSocket:receiveStop ()
Stops receiving datagram packets on this socket.
udpSocket:send (data, addr, port[, callback])
Sends the specified datagram packet on this socket to the specified address and port number.

Parameters:

  • data string the datagram packet as a string.
  • addr string the IP address.
  • port number the port number.
  • callback function an optional callback function to use in place of promise. (optional)

Returns:

    jls.lang.Promise a promise that resolves once the data has been sent.

Usage:

    local s = UdpSocket:new()
    s:send('Hello', '239.255.255.250', 1900)
udpSocket:close ([callback])
Closes this socket.

Parameters:

  • callback function an optional callback function to use in place of promise. (optional)

Returns:

    jls.lang.Promise a promise that resolves once this socket is closed.
generated by LDoc 1.4.6