Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-05-2010, 10:47 PM   #1
Registered: Mar 2008
Distribution: Ubuntu
Posts: 243

Rep: Reputation: 32
sendto function call in UDP client program

The following is the UDP client code I am using.

int sockfd;
struct sockaddr_in serv_addr;
sockfd = socket(PF_INET, SOCK_DGRAM, 0);
if(sockfd == -1)
	cout<<"unable to open the socket"<<endl;
bzero(&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr("");
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";
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?

Last edited by chakka.lokesh; 01-05-2010 at 10:48 PM.
Old 01-05-2010, 10:53 PM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.

Last edited by paulsm4; 01-05-2010 at 10:55 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
client/server echo program of UDP sockets memisbah Programming 2 04-08-2008 10:27 AM
Multithread udp socket client fails to sendto data dilin Programming 0 04-06-2007 09:07 AM
wireless card udp sendto() question ggeorgak Programming 1 02-11-2007 10:26 AM
how to call C function in FORTRAN program bigapple Programming 5 08-24-2005 12:30 AM
Server Client program using UDP frostmagic Programming 9 11-14-2003 11:06 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:04 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration