Listen to more than one udp socket in Thread Network with KW41Z

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Listen to more than one udp socket in Thread Network with KW41Z

1,181 Views
steffenjahnkepa
Contributor III

Hello,

im using the FREEDOM-KW41Z with the frdmkw41z_wireless_examples_thread_router_eligible_device_freertos Example and UDP Sockets, which are enabled with the SOCK_DEMO macro . My Question is, how can I listen to more than one udp-Socket-Port at the same time? I need this to install a unicast and multicast part. If I'm right, i just can open different ports on the site of the Sender, but can not configure on the Receiver site, to which ports he should listen to? I'm very thankfull for Suggestions how to install this functionality. Thanks!

Has no one an Idea?

Labels (2)
2 Replies

605 Views
estephania_mart
NXP TechSupport
NXP TechSupport

Hello,

It is possible to hear more than one UDP port.

By default the demo will create and bind a socket to the port 1234 you will need to create and bind to another port (available in the range) as it is done with the first one.

To do so you will need to open the app_socket_utils.c file and add the next modifications

/* Server sockets */
static int32_t mSockfd = -1;
static int32_t mSockfdNewCustom = -1;

 

 /* Socket storage information used for RX */
sockaddrIn6_t mSsRx = {0};
sockaddrIn6_t mSsRxNewCustom = {0};

 

////////////////First socket/////////////////
 /* Create a socket for global IP address */
 /* Set local information */
mSsRx.sin6_family = AF_INET6;
mSsRx.sin6_port = UDP_PORT;
IP_AddrCopy(&mSsRx.sin6_addr, &in6addr_any);
/* Create socket */
mSockfd = socket(mSsRx.sin6_family, SOCK_DGRAM, IPPROTO_UDP);
/* Bind socket to local information */
bind(mSockfd, (sockaddrStorage_t*)&mSsRx, sizeof(sockaddrStorage_t));

 ////////////////Second socket///////////////// 
 mSsRxNewCustom.sin6_family = AF_INET6;
 mSsRxNewCustom.sin6_port = 8080; //Choose a port in the correct range
 IP_AddrCopy(&mSsRxNewCustom.sin6_addr, &in6addr_any);
 /* Create socket */
 mSockfdNewCustom = socket(mSsRxNewCustom.sin6_family, SOCK_DGRAM, IPPROTO_UDP);
 /* Bind socket to local information */
 bind(mSockfdNewCustom, (sockaddrStorage_t*)&mSsRxNewCustom, sizeof(sockaddrStorage_t));

 

Also you will need to check the following functions:

  • void APP_InitUserSockets
  • static void APP_InitSocketServer 

 

Best Regards, 

Estephania 

605 Views
steffenjahnkepa
Contributor III

Hello Estephania,

thanks a lot! This works fine!

After your Explanation i wonder why i didn't try that before. :smileywink:

Best Regards,

Steffen