LinuxQuestions.org
Visit Jeremy's Blog.
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 09-03-2007, 05:45 AM   #1
mallikk_in
Member
 
Registered: Jun 2006
Posts: 34

Rep: Reputation: 15
SO_KEEPALIVE :should it be in client/server?


writing application which require
when client dies or conxn breaks(network problem), server handling the client should exit,

tried if read/recv fails in server ,then server can exit, but 1 it didnt wrk and later felt its blocking call,
after killing client ie. kill -9 client , server handling client still rung?

sending a code flow,

in server
main()
{
socket()
bind()
listen()
while(1){
nfd=accept()
ret = fork()

if(ret=0)
{
recv(nfd);
while(1);
}
}


In client()
main()
{
socket();
so_optval=1;

if (setsockopt(sfd, SOL_SOCKET, SO_KEEPALIVE, (char *) &so_optval,
sizeof(SO_KEEPALIVE)) == -1)
perror("setsockopt() so_keepalive failed");
else
printf("setsockopt() so_keepalive successful\n");

int val;
val = 30; /* 5 minutes before starting probes */
setsockopt (sfd, SOL_TCP, TCP_KEEPIDLE, &val, sizeof (val));
val = 2; /* 6 probes max */
setsockopt (sfd, SOL_TCP, TCP_KEEPCNT, &val, sizeof (val));
val = 10; /* 10 seconds between each probe */
setsockopt (sfd, SOL_TCP, TCP_KEEPINTVL, &val, sizeof (val));

connect()
send();

}


please correct
 
Old 09-04-2007, 01:44 AM   #2
mallikk_in
Member
 
Registered: Jun 2006
Posts: 34

Original Poster
Rep: Reputation: 15
SO_KEEPALIVE sends SIGPIPE?

in setsockopt,
the size is sizeof(int), sorry for tat typo error,


I handled for sigpipe signal, in server and client , because SIGPIPE is sent to server/client which uses SO_KEEPALIVE when connection is broken.

signal(SIGPIPE, shut_down);
void shut_down(int n){
printf("Socket broken , Exiting server.c\n");
exit(1);
}

still i'm finding its not works , also executed as root user?
is it required to call connect () to find socket connection is it broken,
but i think SO_KEEPALIVE sends SIGPIPE handling it should work.
 
Old 09-04-2007, 12:27 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
  


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
Setting up thin-client-server/server ctkroeker Linux - Networking 2 09-06-2006 07:55 PM
can not connect to my pureftp server from Linux client, but i can from windows client bonito Suse/Novell 5 03-16-2005 09:45 PM
Showing CLIENT<-server->INTERNET connection from server. druuna Linux - Networking 2 05-03-2004 01:33 PM
Refresh client user list at autentication client/server network. robertoneto123 Linux - Networking 0 11-11-2003 10:38 AM
Client server model using linux server and w2k clients? siva_bhavani Linux - Networking 2 09-29-2003 03:35 PM


All times are GMT -5. The time now is 12:36 PM.

Main Menu
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