Create connection to a WebSocket API created on AWS using the webcomponents library in zephyr

64 views Asked by At

I have created a WebSocket API on AWS which i can connect to using the webcomponents library from python, and also using the WebSocket tester on PieSocket.

However, when I am trying to connect from a NRF-BOARD - 9160-dk using the zephyr library's websockets functions, I can't seem to connect to the WebSocket API.

Right now, the code which is not connecting properly is as follows (an URL is successfully obtained from the getaddrinfo() call):

struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
struct addrinfo hints = {
    .ai_flags = 0,
    .ai_family = AF_INET,
    .ai_socktype = SOCK_STREAM,
    .ai_protocol = 0,
};
// The resulting address info struct.
struct addrinfo *result;

 int ip_address = getaddrinfo("abcde123.execute-api.eu-xxx.amazonaws.com", NULL, &hints, &result);

// Print the IP address in the result
struct sockaddr_in *addr = (struct sockaddr_in *)result->ai_addr;
char ip[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &addr->sin_addr, ip, sizeof(ip));
printk("IPv4 address: %s\n", ip);
printk("Protocol: %d\n", result->ai_protocol);
printk("Socket type: %d\n", result->ai_socktype);
printk("Socket family: %d\n", result->ai_family);

int sock = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (sock < 0) {
    printk("Socket creation failed\n");
    return;
}

ret = connect(sock, result->ai_addr, result->ai_addrlen);
if (ret < 0) {
    LOG_ERR("Failed to connect to %s:%d", SERVER_ADDR4, SERVER_PORT);
    close(sock4);
    close(sock);
}

Here it fails to connect to the server, although an ip_adress is obtained through the given URL (which is an wss:// URL). It is saying that the problem is on the server side, but I don't know where and how, since i can connect to the WebSocket API using other sources.

0

There are 0 answers