Step 2: Adding TCP Comms |
Top Previous Next |
This and other projects in the Code Examples section are published on our website under the name "test_wln_lib".
Now let's take the previous example and create a TCP socket that will accept connections over the Wi-Fi interface. We will make a simple loopback socket that echoes back the data.
Only main.tbs needs to be changed from the previous example. The socket is configured in on_sys_init(). Notice how we don't just pick a random socket number to use. We obtain the socket from the SOCK library by calling sock_get(). This is very important! Once any part of your project uses the SOCK library (and WLN library does), all other parts of your project must do the same. Mess will ensue if you fail to handle socket numbers correctly. In the code below, we first call wln_start() and then configure the loopback socket. There is no significance to this order and you can reverse it. Same goes for on_sock_data_arrival(). There is no special reason to call wln_proc_data() first, and handle the loopback socket next. You can reverse the order and everything will still work.
|