UDP communication in MQX

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

UDP communication in MQX

ソリューションへジャンプ
2,016件の閲覧回数
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,727件の閲覧回数
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,726件の閲覧回数
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,726件の閲覧回数
cerma
Contributor IV

Hi Daniel,

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

0 件の賞賛
返信
1,728件の閲覧回数
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,726件の閲覧回数
cerma
Contributor IV

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

0 件の賞賛
返信