Home/Support/Support Forum/udp send receive communication in wiem9210 module
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

udp send receive communication in wiem9210 module

0 votes
hi folks,

presently i written a sample source code for sending data through udp socket but i am getting abort exeception error while sending the data .pls provide valuable sugestion for to resolve my probem....

The sample udp send source code and exection output shown below ,
struct sockaddr_in si_me, si_other,si_other2;
struct sockaddr_in si_send;
int rlen = sizeof(si_other),slen = sizeof(si_other2),recv_len;
char buf[BUFLEN];
int send_rcv=0;
#define MSG_7 7
#define THREAD_STACK_SIZE 16384

void udp_app_send(unsigned long unused)

SOCKET sock;

//create a UDP socket
struct sockaddr_in addr = {0};

if ((sock=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
// zero out the structure
memset((char *) &si_send, 0, sizeof(si_send));

si_send.sin_family = AF_INET;
si_send.sin_port = htons(NA_UDP_PORT_SND);
si_send.sin_addr.s_addr = htonl(INADDR_ANY);

//bind socket to port
if( bind(sock , (struct sockaddr*)&si_send, sizeof(si_send) ) == -1)
printf("Waiting for send data...\n");
//keep listening for data

strcat (buf,"_Append");

if (sendto(sock,buf,recv_len+MSG_7, 0, (struct sockaddr *)&addr,sizeof(addr)) == -1)
memset((char *) &buf, 0, sizeof(buf));
printf("Message_Sent :%s\n" , buf);
printf("Transmitted packet from %s Port No:%d\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port)); //print details of the client/peer and the data transmitted

printf("after send_rcv : %d",send_rcv);




hyperterminal output:

NET+OS Version
Copyright (c) 1997-2011, 2013 Digi International, Inc.

PLATFORM: connectwiem9210 4M/8M [Jul 08 2014 14:37:30]
APPLICATION: FTP SERVER [Jul 16 2014 17:45:40]
Wireless IP address is
Wireless subnet mask is
Wireless IP address of default gateway to other networks is
Wireless Network type: Access Point/Infrastructure
Wireless SSID is Phoenix1
Wireless Protocol: 802.11b
Wireless powersave disabled
Wireless Security: Open
Serial channels will use a baud rate of 9600
This board's serial number is N99999999
This board's Wireless MAC Address is 00:40:9D:4A:75:1C
After board is reset, start-up code will wait 16 seconds
Press any key in 16 seconds to change these settings.

Serial CLI Started
IAM:AUTO-CONFIGURED IPv6 FE80::240:9DFF:FE4A:751C on wln0:3
IAM:STATIC IPv4 on wln0
Network IP configured.
UDP Bridge started
Waiting for data...
FTP Bridge started
Waiting for send data...
IAM:AUTOIP IPv4 on wln0:0
MeWaiting for data...
Abort Exception
Thread Name: Root Thread
Thread ID:54485244
Thread Stack Start Address:0078AB48
Thread Stack End Address:00790B47
Program Counter :0017C44C
Stack Pointer :00785B40
Current program status Register :20000097
R00:00000001 R01:00000004
R02:00000804 R03:0026F7FC
R04:00000000 R05:0026FAEC
R06:0078250C R07:0026FAE0
R08:00178CEC R09:00000000
R10:00000000 R11:00790964
asked Jul 16, 2014 in NET+OS by vijayakumar New to the Community (5 points)
reshown Jul 27, 2014 by kavya

Please log in or register to answer this question.

1 Answer

0 votes

Lets look at a couple of lines in your program as listed herein:

struct sockaddr_in addr = {0};
You create an address structure called addr and you zero same out.

if (sendto(sock,buf,recv_len+MSG_7, 0, (struct sockaddr *)&addr,sizeof(addr)) == -1)

You call API sendto using address structure addr (zeroed out above) but you never set address structure addr to any address, port or family. I can't imagine anything good coming out of this.

I believe you need to set the family, port and address of structure addr to the port, address and family of where you want your packet going (the destination).
answered Jul 16, 2014 by dakotas_dad Veteran of the Digi Community (694 points)
hi dakotas_dad,

i  used below function prototype only....
if (sendto(sock,buf,recv_len+MSG_7, 0, (struct sockaddr *)&si_send,sizeof(si_send)) == -1)

still all the things are correct means why i am getting abort exception ....
Pls provide me valuable comment regarding the abort exception why it is throughing error and how to resolve the Problem  I am waiting for your reply....
A couple of things.

Prior to your following code:
if (sendto(sock,buf,recv_len+MSG_7, 0, (struct sockaddr *)&addr,sizeof(addr)) == -1)

What are the values of addr assigned to?

Also if you replace the call to function die with the following:
printf("error returned from sendto was %d\n", getErrno()); What do you get? getErrno() requires #include "sockapi.h" but if you are using sendto and bind you are probably already including this.
hi dakotas_dad,
 i am getting error no as "121"
.pls give valuable guidance to resolve the issue ..
Error code 121 equates to "Destination Address Required"

Here is what I want you to do. First tell us what IP address you want to send a packet to (using sendto). Next show us the line or lines of code where you believe you are setting the DESTINATION address in the address structure that will be used by sendto for sending the packet out.
Hi,after updating the destination address also it shows abort  exception.....
Ever it is going wrong I can't to find it out .  I need ur valuable assistance .....