UDP communication in MQX

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

UDP communication in MQX

Jump to solution
1,210 Views
cerma
Contributor IV

Hello,

is there any example for this use case:

Mask: 255.255.255.0
My device IP: 192.168.0.1

I need UDP communication working as client to server. My device would be server.
I am receiving packets from port 5000 and any IP within same network as my device. This packet arrives with source port (always same) 5001.
After I process incoming message, I have to send response to IP address from which I have got received request with source port set to 5000 (my receive port) and 5001 as destination port (port that I have get from request).

Is there any example for this? Do I need 2 sockets for this or one is enough? I have found example AN4644CW and there are two sockets for something familiar to my problem but when I have tried to change it for my needs, communication always got stuck. Currently I am using 2 sockets as it in example and closing and reopening them but it does not working.

0 Kudos
Reply
1 Solution
921 Views
danielchen
NXP TechSupport
NXP TechSupport

I attached demo.c and config.h already,  if you can't download it or you can't see them, you can submit a request

How to submit a new question for NXP Support 

My test result is as following.

pastedImage_1.png

Regardd

Daniel

View solution in original post

0 Kudos
Reply
4 Replies
921 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Jaroslave:

I think you only need one socket to communicate.

I made a simple udp server demo , I modified this demo based on Freescale_MQX_4_2\rtcs\examples\eth_to_serial, you can replace with the attached files.

The udp server source port is 5000, it can receive all packets. 

If you need to receive packets only with port 5001, you can change this line in demo.c

        server_socket_addr.sin_addr.s_addr = INADDR_ANY;  ->         server_socket_addr.sin_addr.s_addr = 5001;

Regards

Daniel

0 Kudos
Reply
921 Views
cerma
Contributor IV

Hi Daniel,

I think you forgot to attach files with your example. Could you please attach them?

0 Kudos
Reply
922 Views
danielchen
NXP TechSupport
NXP TechSupport

I attached demo.c and config.h already,  if you can't download it or you can't see them, you can submit a request

How to submit a new question for NXP Support 

My test result is as following.

pastedImage_1.png

Regardd

Daniel

0 Kudos
Reply
921 Views
cerma
Contributor IV

Thank you very much. It is working now. :smileyhappy:

0 Kudos
Reply