LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 01-05-2010, 11:47 PM   #1
chakka.lokesh
Member
 
Registered: Mar 2008
Distribution: Ubuntu
Posts: 211

Rep: Reputation: 32
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?

Last edited by chakka.lokesh; 01-05-2010 at 11:48 PM.
 
Old 01-05-2010, 11:53 PM   #2
paulsm4
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 11:55 PM.
 
  


Reply


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 11:27 AM
Multithread udp socket client fails to sendto data dilin Programming 0 04-06-2007 10:07 AM
wireless card udp sendto() question ggeorgak Programming 1 02-11-2007 11:26 AM
how to call C function in FORTRAN program bigapple Programming 5 08-24-2005 01:30 AM
Server Client program using UDP frostmagic Programming 9 11-15-2003 12:06 AM


All times are GMT -5. The time now is 12:15 AM.

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