first i am creating socket, with that socket descriptor i am sending some no. of bytes through sendto(....) function.
At the time of receiving through recvfrom(....) function, my code was hanging if the specified destination address is not available. Suppose if destination is available the it's working correctly... Why this is happening

In the recvfrom() function, use "MSG_DONTWAIT" flag in the 4th argument(which is the flag) and see whether it solves your problem.

By default, the method will wait until it gets a message from the mentioned address, and your program will proceed only after that.

Read the manual for recvfrom()

Hope that helps.....

even if i am keeping MSG_DONTWAIT flag, it showing resource temporarily unavailable, but actually resource is available

can you share the code segment for both the sender and receiver programs where you are making the communication, also mention which compiler you are using and which platform(windows or Linux)

first creating socket with----> socket(AF_INET,SOCK_DGRAM,0),
then sending by ----> sendto(socketid,buffer,150,0,(struct sockaddr *)&sock,sizeof(sock))

then receiving by--------> recvfrm(socketid,buffer,150,0,(struct sockaddr*)&sock,sizeof(sock))

In struct sockaddr i am giving destination IP address ,, IF destination is available then immediately its replying other wise waiting for data to receive from destination

This article has been dead for over six months. Start a new discussion instead.