UDP communication in MQX

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

UDP communication in MQX

跳至解决方案
2,020 次查看
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.

标记 (4)
0 项奖励
回复
1 解答
1,731 次查看
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 项奖励
回复
4 回复数
1,730 次查看
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 项奖励
回复
1,730 次查看
cerma
Contributor IV

Hi Daniel,

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

0 项奖励
回复
1,732 次查看
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 项奖励
回复
1,730 次查看
cerma
Contributor IV

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

0 项奖励
回复