nRF5 IoT SDK
v0.9.0
|
This example demonstrates how the BSD Socket Interface can be to send data to a remote TCP port. Remote port number 9000 is assumed in this example. Request and response formats used for this example are described in sections TCP Request Format and TCP Response Format, respectively.
The client will attempt to create a socket and connect to the remote server until successful. Once connected, it will send and receive sequence numbers from 0 to 100, using the same format as the Client example.
Once a packet is sent, blocking I/O is used to receive a packet, waiting until successfully received. The TCP server could be a PC application communicating to the TCP client on the kit, or another devkit running the Server example.
Since this example can run on a PC, it is not using any LEDs or buttons on the nRF5x DK.
The example can also be compiled on a Linux host to demonstrate the portability of the BSD Socket Interface. Simply run
to compile it.
This section summarizes the usage of nRF5x resources and common modules in the examples apart from the IoT 6lowpan and lwIP stack library.
Module | Inclusion/Usage | Description |
---|---|---|
Timer | 1 | Timer for lwIP. |
Button | No | No buttons are used. |
LEDs | No | No buttons are used. |
Adv Data Encoder | Yes | The device name used is 'TCP_Socket_Client', IPSP Service UUID is included in the UUID list. |
Scheduler | No | Scheduler is not used for processing stack events. |
UART Trace | Included not enabled | Tracing is included but not enabled by default. |
The source code and project file of the example can be found at: <InstallFolder>/examples/iot/socket/tcp/client
See Connecting devices to the router for a list of relevant Linux commands.
Below is a python server example that listens on port 9000 and sends back responses for requests received on the port. Request and response structure are according to the format specified in sections TCP Request Format and TCP Response Format respectively.