LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   sendto function call in UDP client program (https://www.linuxquestions.org/questions/programming-9/sendto-function-call-in-udp-client-program-780154/)

chakka.lokesh 01-05-2010 10:47 PM

sendto function call in UDP client program
 
The following is the UDP client code I am using.

Code:

int sockfd;
struct sockaddr_in serv_addr;
sockfd = socket(PF_INET, SOCK_DGRAM, 0);
if(sockfd == -1)
{
        cout<<"unable to open the socket"<<endl;
        exit(1);
}
bzero(&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr("172.16.1.2");
serv_addr.sin_port = htons(9999);
if( sendto(sockfd,message,strlen(message)+1,0,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0 )
{
        cout<< "unable to write to the socket descriptor\n";
        exit(1);
}
close(sockfd);

Even the server is down, sendto function is not returning -1.
Instead, it is returning the length of the message as if it is success.

can any body please help me tracing the bug?

paulsm4 01-05-2010 10:53 PM

Sorry - not a bug.

UDP, as you probably know, is inherently "unreliable". The status simply means the message was sent - the protocol does *not* guarantee that a message sent is also a message received.


All times are GMT -5. The time now is 10:32 PM.