2 Attachment(s)
Data transfer in V2V communication (Fedora11)
hi developers,
can anybody help me direct to the right forum for wireless vehicular communication. i am using NCTUns simulator and having problem while receiving message from an OBU. sending a message works properly but recving creates problem and fails. i am using exactly the same function as used by the developers in the demos but still no luck. i copy the code attch the screen shots to have a look please help me i have got only a few days left to submit my result and looking forward for your kind help.
sendto() and recvfrom() are used for message transfer. they both return >-1 if they are executed successfully. please have a look in the screenshots. agentClientReportStatus is the built in packet format which im using here whose fields i filled manually are in the code below.
agentClientReportStatus *message,*mssg;
int remainTime,n,n2,n3,i,sendingaddress,value;
sockaddr_in cli_addr;
timeval now;
sendingaddress=255;
sprintf(portNumStr, "%d", agentUDPportNum);
myUDPsockfd = passiveUDP(portNumStr);
printf("Agent(%d) created myUDPsockfd %d\n", mynid, myUDPsockfd);
if (myUDPsockfd < 0) {
printf("Agent(%d): Creating myUDPsockfd failed\n", mynid);
exit(0);
}
n = fcntl(myUDPsockfd, F_SETFL, O_NONBLOCK);
message = new agentClientReportStatus;
mssg = new agentClientReportStatus;
double lastTime = (double) now.tv_sec * 1000000 + (double) now.tv_usec;
while(1)
{
len = sizeof(cli_addr);
n2 = recvfrom(myUDPsockfd,(char *) &mssg, sizeof(struct agentClientReportStatus), 0, (struct sockaddr *) &cli_addr,&len);
if (n2 < 0) {
printf("Agent(%d) recvFrom() failed and n= %d\n", mynid, n2);
}else
{
printf("Message received from : %d and of Sequence Number: %d",mssg->nid,mssg->seqNum);
}
}
n = getCurrentPositionOfAGroupOfNode(myTCPsockfd, mynid, 1, &NPArray,
numNodeInThisGroup, 1);
if(n>-1)
{
for (i=0; i<numNodeInThisGroup; i++)
{
if (NPArray->nid == mynid)
{
// A mobile node should not send a message to itself.
NPArray++;
continue;
}
ax=NPArray->x;
ay=NPArray->y;
sprintf(hostname, "1.0.1.%d", sendingaddress);
//hostname="1.0.1.255";
value = 1;
setsockopt(myUDPsockfd , SOL_SOCKET , SO_BROADCAST , &value , sizeof(value));
len = sizeof(cli_addr);
memset( &cli_addr, 0, sizeof(cli_addr) );
cli_addr.sin_family = AF_INET;
cli_addr.sin_port = htons(agentUDPportNum);
cli_addr.sin_addr.s_addr = inet_addr( "1.0.1.255" );
message->x = 111.0000;
message->y = 333.0000;
message->type = AGENT_CLIENT_REPORT_STATUS;
message->nid = NPArray->nid;
message->moreMsgFollowing = 1;
message->acceleration = 5;
message->speed = 19;
message->direction = 90;
message->seqNum = 5;
message->timeStamp=lastTime;
message->TTL=3;
n3 = sendto(myUDPsockfd, message, sizeof(struct agentClientReportStatus), 0, (struct sockaddr *) &cli_addr, len);
if (n3 < 0) {
printf("Agent(%d) Sendto() failed\n", mynid);
//exit(0);
}
else
{
printf("Message sent from : %d and of sequence number: %d and n3= %d\n",message->nid,message->seqNum, n3);
}
NPArray++;
}
//free(message);
}