UDP receive with socket API

Hi,
I am using nrf9151-DK to send and receive data over UDP protocol. Firstly, I tried to use AT commands to send and receive meassages as described here, I had no isuues here. However when using socket API, I am no able to receive any data.

Project config:

# Networking
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=n
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_OFFLOAD=y
CONFIG_POSIX_API=y

# Modem library
CONFIG_NRF_MODEM_LIB=y

# LTE link control
CONFIG_LTE_LINK_CONTROL=y
#CONFIG_LTE_LC_PSM_MODULE=y
CONFIG_LTE_LC_MODEM_SLEEP_MODULE=y
CONFIG_LTE_LC_MODEM_SLEEP_NOTIFICATIONS=y

# Logging
CONFIG_SERIAL=y
CONFIG_LOG=y
CONFIG_FPU=y


Code:
int modem_send_hello(void)
{
	const char *SERVER_HOSTNAME = "xxx.xxx.xxx.xxx";
	const int SERVER_PORT = 65535;
	const char *message = "message";

	int err;
	int sock;
	struct sockaddr_storage host_addr;
	char recv_buf[64];
	struct sockaddr_in *server4 = ((struct sockaddr_in *)&host_addr);

	server4->sin_family = AF_INET;
	server4->sin_port = htons(SERVER_PORT);

	inet_pton(AF_INET, SERVER_HOSTNAME, &server4->sin_addr);

	sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (sock < 0)
	{
		LOG_ERR("Failed to create UDP socket, error: %d\n", errno);
		return -errno;
	}

	err = connect(sock, (struct sockaddr *)&host_addr, sizeof(struct sockaddr_in));
	if (err < 0)
	{
		LOG_ERR("Failed to connect socket, error: %d\n", errno);
		close(sock);
		return err;
	}

	LOG_INF("Sending: %s", message);
	err = send(sock, message, sizeof(message) - 1, 0);
	if (err < 0)
	{
		LOG_ERR("Failed to transmit UDP packet, error: %d\n", errno);
	}

	err = recv(sock, recv_buf, sizeof(recv_buf) - 1, 0);
	if (err < 0)
	{
		LOG_ERR("Failed to receive UDP packet, error: %d\n", errno);
	}
	recv_buf[err] = 0;
	LOG_INF("Received: %s", recv_buf);

	close(sock);

	return 0;
}


Code hangs on recv() function as it does not receive any data.

Parents Reply Children
Related