1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 01:09:47 +01:00
RIOT/examples/posix_select
2024-02-05 00:45:42 +01:00
..
main.c examples: add posix_select example 2020-07-01 18:10:26 +02:00
Makefile treewide: replace gnrc_netdev_default with netdev_default 2021-09-06 15:43:40 +02:00
Makefile.ci boards/weact-g030f6: add new board 2024-02-05 00:45:42 +01:00
README.md examples: add posix_select example 2020-07-01 18:10:26 +02:00

examples/posix_sockets

This application is a showcase for RIOT's POSIX select support. To keep things simple this application has only one-hop support and no routing capabilities.

Usage

Build, flash and start the application:

export BOARD=your_board
make
make flash
make term

The term make target starts a terminal emulator for your board. It connects to a default port so you can interact with the shell, usually that is /dev/ttyUSB0. If your port is named differently, the PORT=/dev/yourport (not to be confused with the UDP port) variable can be used to override this.

Example output

The application starts 4 UDP servers on a selection of different ports that wait for input simultaneously:

2019-12-17 16:36:45,559 # RIOT select example application
2019-12-17 16:36:45,561 # Started UDP server at [fe80::14ac:fb65:106b:1115]:1350
2019-12-17 16:36:45,562 # Started UDP server at [fe80::14ac:fb65:106b:1115]:4973
2019-12-17 16:36:45,562 # Started UDP server at [fe80::14ac:fb65:106b:1115]:6717
2019-12-17 16:36:45,562 # Started UDP server at [fe80::14ac:fb65:106b:1115]:9673

If you do not see any output you might need to reset the node. Either, by pressing the hardware reset button on the board or by running

make reset

There is no shell in this application. You can use the posix_sockets example from another board to send a packet to the node:

> udp send fe80::14ac:fb65:106b:1115 6717 "Hello World!"
2019-12-17 16:47:01,789 # udp send fe80::14ac:fb65:106b:1115%6 6717 "Hello World!"
2019-12-17 16:47:01,795 # Success: send 12 byte to fe80::14ac:fb65:106b:1115:6717

On the board with the posix_select example you will see then something like this:

2019-12-17 16:47:01,796 # Received data from [fe80::589d:9386:2208:6579]:192:
2019-12-17 16:47:01,796 # Hello World!

Alternatively, with native or if your host also can connect to the board, you can also use netcat to send multiple packets simultaneously. E.g. when the node is connected to the host via the interface tapbr0:

echo -ne "Hello World!" | nc -6u "fe80::78b9:ecff:fe96:8279%tapbr0" 4973 & \
    echo -ne "Hello Space!" | nc -6u "fe80::78b9:ecff:fe96:8279%tapbr0" 1350
killall nc

This is what the native node will then show:

Received data from [fe80::3ccc:8dff:fe9f:9991]:14279:
Hello World!

Received data from [fe80::3ccc:8dff:fe9f:9991]:58817:
Hello Space!