I use tad tool,watch the IP State ,I find the pc's broadcast datagram has been discarded by mqx,the reason is illegal destination.
I have send broadcast datagram nine times,the picture as follow
岳永超
北京云天创科技有限公司 ATZGB(BeiJing) Co.,Ltd.
Mob:18101210380
Fax:010-82176393-808
北京市海淀区上地7街(信息路2号)国际创业园2号楼20B
yueyongchao@yeah.net
From: yueyongchao@yeah.net
Date: 2014-10-08 17:11
To: jive-186488485-4wrl-2-9h4q
Subject: Re: Re: - how to use UDP in mqx to receive a broadcast datagram .eg. (use udp to recv data from 192.168.1.255)
code has been Modified as followed.but it still has something wrong.
the mqx(192.168.1.222) can send a datagram to 192.168.1.255 and my pc(192.168.1.112) can recv mqx's broadcast datagram.
but my pc send a broadcast datagram to 192.168.1.255,mqx can't recv pc's broadcast datagram.
sendsock = socket(PF_INET, SOCK_DGRAM, 0);
/* Bind the socket to the Telnet port */
addr.sin_family = AF_INET;
addr.sin_port = 5055;
//addr.sin_addr.s_addr = ENET_IPADDR;
addr.sin_addr.s_addr = INADDR_ANY;
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = 5055;
dest_addr.sin_addr.s_addr = INADDR_BROADCAST;
error = bind(sendsock, &addr, sizeof(addr)); //return_error_if(error != RTCS_OK)
timedelay(100);
rlen = sizeof(dest_addr);
sendto(sendsock, senddata, strlen(senddata), 0,&dest_addr, rlen);
while(1)
{
ret = RTCS_selectset(&sendsock, 1, 1000);
if(ret == sendsock)
{
count = recvfrom(sendsock, recvdata, 512, 0, (struct sockaddr *) &dest_addr,&rlen);
if(count == RTCS_ERROR)
{
;
}
else
{
if(count>0)
{
//_io_write(serial4_fd, recvdata, count);
//_time_delay(1000);
//memset(recvdata,0,sizeof(recvdata));
//count = 0;
//cmd_reply_len = phone_cmd_analsys((uint_8*)recvdata,count);
//sendto(sendsock, phone_reply, cmd_reply_len, 0,&dest_addr, rlen);
sendto(sendsock, "123", 3, 0,&dest_addr, rlen);
memset(phone_reply,0,PHONE_REPLY_LEN);
count = 0;
}
}
}
}
岳永超
北京云天创科技有限公司 ATZGB(BeiJing) Co.,Ltd.
Mob:18101210380
Fax:010-82176393-808
北京市海淀区上地7街(信息路2号)国际创业园2号楼20B
yueyongchao@yeah.net
From: Martin Latal
Date: 2014-10-08 15:19
To: yongchao yue
Subject: Re: - how to use UDP in mqx to receive a broadcast datagram .eg. (use udp to recv data from 192.168.1.255)
how to use UDP in mqx to receive a broadcast datagram .eg. (use udp to recv data from 192.168.1.255)
reply from Martin Latal in MQX Software Solutions - View the full discussion
SO_BROADCAST is used for sending broadcast datagrams, not for receiving. We don't currently have this option in RTCS.
OPT_RECEIVE_PUSH is for a TCP socket, not UDP.
to receive a broadcast from any interface, you should bind the UDP socket to zero ip address (INADDR_ANY) and your port (per your source code, seems you already have this).
It should be enough to get this datagram with the recvfrom() function. Remove the two socket options from your code and give it a try.
-Martin
Did your question get answered?
If so, say thanks by clicking Correct Answer in the community thread!
Reply to this message by replying to this email, or go to the message on Freescale Community
Start a new discussion in MQX Software Solutions by email or at Freescale Community
Following how to use UDP in mqx to receive a broadcast datagram .eg. (use udp to recv data from 192.168.1.255) in these streams: Inbox