Failed to connect to a TCP server from a RIOT TCP client

I am trying to set up a TCP connection between two riot nodes using the sample code given here. The server node works fine and I can connect to it and send messages from my Linux machine, however, the client node cannot connect to any TCP server by specifying an ipv6 address (with tap/bridge) and a port. Could anyone help me with this? Thank you!

What IP do you use? Global, link-local or ULA? Have you checked the traffic with Wireshark?

I tried both with and without a global prefix on both the bridge and my riot node. Below is the riot node and tapbr0 with global prefix.


I used tcpdump -i tapbr0 to investigate outgoing files, however, seems that packages are sent out only at the node creation time. When I try to build connection by using sock_tcp_connect( &sock , &remote , 0 , 0 ), nothing showed up.

It looks like you don’t route your packets. That is a topic for itself. For testing purposes you can just use the interface name. Something like fe80::bcac:3aff:fe91:4944%tapbr0. As long as the client is running on the same node, this should work.

Hi, thank you for your reply!
If my riot node is a TCP server, then I can connect to it by using cmd nc -6v fe80::bcac:3aff:fe91:4944%tapbr0 <port_num> on my Linux machine, however, I am trying to connect a riot client node to another TCP server (which could be either a Linux machine or another riot node). And I don’t understand how should I route pkt from the riot client node to any other TCP server. Below is my TCP client source code:

#include "net/af.h"
#include "net/ipv6/addr.h"
#include "net/sock/tcp.h"
#include "net/sock/tcp.h"
#include "net/af.h"
#include <string.h>
#include "thread.h"
#include "shell.h"
#include "shell_commands.h"
/* socket includes */
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#include "xtimer.h"
 
uint8_t buf[128];
sock_tcp_t sock;

int client(int argc, char **argv){

    (void) argc;
    (void) argv;

    int res;
    sock_tcp_ep_t remote = SOCK_IPV6_EP_ANY;
 
    remote.port = 12345; // This is the remote server port number
    puts("Starting here!");

    ipv6_addr_from_str((ipv6_addr_t *)&remote.addr,"fe80::bcac:3aff:fe91:4943"); // This is the remote server address
                                                                                 // Should this be the address of tapbr0 or the address
                                                                                 // of another riot node (if I have another riot server node)?

    while(1){

        if ( sock_tcp_connect( &sock , &remote , 0 , 0 ) < 0 ) {// This step always fails!
        
            puts("Error connecting sock");
            xtimer_sleep(2);
            continue;
        }

        puts("Sending \"Hello!\"");
        if ( (res = sock_tcp_write(&sock, "Hello!", sizeof("Hello!"))) < 0) {
            puts("Errored on write");
        }else{
            if ((res = sock_tcp_read(&sock, &buf, sizeof(buf),
                                    SOCK_NO_TIMEOUT)) <= 0) {
                puts("Disconnected");
            }
            printf("Read: \"");
            for (int i = 0; i < res; i++) {
                printf("%c", buf[i]);
            }
            puts("\"");
        }
        sock_tcp_disconnect(&sock);

        xtimer_sleep(2);

    }

    return 0;

}

static const shell_command_t shell_commands[] = {
    { "send", "send tcp msg", client },
    { NULL, NULL, NULL }
};

int main(void)
{
    char line_buf[SHELL_DEFAULT_BUFSIZE];
    shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
    return 0;
}

Thank you!

Between two RIOT nodes, you can just use RPL. But you need a RPL router as well. There is a tutorial about this. For the the part on Linux, you can refer to this forum topic.