Interface: tos.lib.net.6lowpan.UDPClient

interface UDPClient

Commands
command error_t connect(ip6_addr_t *addr, uint16_t port) 'Connecting' a UDP socket fixes the remote address and port.
command error_t listen(uint16_t port) 'Listening' to a socket binds the local port to a fixed number and allows the socket to receive packets.
command error_t send(uint8_t *buf, uint16_t len)
command error_t sendTo(ip6_addr_t *addr, uint16_t port, uint8_t *buf, uint16_t len) Send a datagram to a remote host.

Events
event void receive(ip6_addr_t *addr, uint16_t port, uint8_t *buf, uint16_t len) A datagram has been received.
event void sendDone(error_t result, void *buf) The previous send or sendTo command has completed.

Commands - Details

connect

command error_t connect(ip6_addr_t *addr, uint16_t port)

'Connecting' a UDP socket fixes the remote address and port. Once fixed, you can send datagrams with the 'send' command. You can un-fix the socket by passing NULL as the argument.

listen

command error_t listen(uint16_t port)

'Listening' to a socket binds the local port to a fixed number and allows the socket to receive packets. If you call send or sendto on an unbound socket, a dynamic local port is assigned. Pass 0 to unbind the port.

send

command error_t send(uint8_t *buf, uint16_t len)

sendTo

command error_t sendTo(ip6_addr_t *addr, uint16_t port, uint8_t *buf, uint16_t len)

Send a datagram to a remote host. Call 'connect' on a socket before calling 'send'. If a local port has not yet been assigned, a dynamic one will be assigned by these commands. Both commands are asynchronous and will generate the 'sendDone' event once the datagram has been sent.

Events - Details

receive

event void receive(ip6_addr_t *addr, uint16_t port, uint8_t *buf, uint16_t len)

A datagram has been received. Datagrams are only received on sockets that have had 'listen' called to assign a local port, or have used the 'send' or 'sendTo' command.

sendDone

event void sendDone(error_t result, void *buf)

The previous send or sendTo command has completed.