[riot-notifications] [RIOT-OS/RIOT] start a udp server that listens only to one client and port (#11894)

talalong notifications at github.com
Tue Jul 23 17:36:49 CEST 2019


I am trying to create `udp` server with `gnrc_networking` base on [this](https://riot-os.org/api/group__net__sock__udp.html?#ga89562920ad89fe0e098fc989e3b064ec) for my samr21-xpro.

This code below works properly, but I want the UDP server to listen to only one client (ipv6 address) and its port. Therefore I have two questions:

1. Is it possible to force the server listening to only one ipv6 address and its port?
2. How can I get the client's address and port as string using `remote` variable?

```
sock_udp_ep_t local = SOCK_IPV6_EP_ANY;
    sock_udp_t sock;
    local.port = 8080;
    puts("starting udp serser at 8080");
    if (sock_udp_create(&sock, &local, NULL, 0) < 0)
    {
        puts("Error creating UDP sock");
        return NULL;
    }
    while (1)
    {
        sock_udp_ep_t remote;
        ssize_t res;
        if ((res = sock_udp_recv(&sock, buf_server, sizeof(buf_server), SOCK_NO_TIMEOUT,
                                 &remote)) >= 0)
        {
            puts("Received a message from ???); // remote ???
             if ((res > 0) && (res < 99))
            {
                buf_server[res] = '\0';   /* add the null byte so buffer now holds a string */
                puts((char *)buf_server); /* write this string to the display */
            }
            if (sock_udp_send(&sock, buf_server, res, &remote) < 0)
            {
                puts("Error sending reply");
                return NULL;
            }
        }
    }
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/issues/11894
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190723/fe197e26/attachment.htm>


More information about the notifications mailing list