niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » *nix » Linux » development » apps
client server programming
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
Author Message
pietro
*nix forums beginner


Joined: 28 Feb 2006
Posts: 3

PostPosted: Mon Jul 17, 2006 8:46 am    Post subject: client server programming Reply with quote

hi all, I'm deploying a client/server application where the connection
is implemented by a socket.
I have a problem. When I close and restart client, the connection with
server application is lost and I cannot restore it. The only way I
found to restore it is to kill and restart both server and client.

Is it possible to re-establish my old connection with server via client
restart only?
Back to top
Josef Moellers
*nix forums Guru


Joined: 28 Feb 2005
Posts: 426

PostPosted: Mon Jul 17, 2006 10:59 am    Post subject: Re: client server programming Reply with quote

pietro wrote:
Quote:
hi all, I'm deploying a client/server application where the connection
is implemented by a socket.
I have a problem. When I close and restart client, the connection with
server application is lost and I cannot restore it. The only way I
found to restore it is to kill and restart both server and client.

Is it possible to re-establish my old connection with server via client
restart only?

If you write "I cannot restore it": what is the error you get?
How do you "close and restart client"? Is the socket correctly close()ed?

If the error message is something like "address already in use", you
might want to look at the SO_LINGER socket option.

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
Back to top
pietro
*nix forums beginner


Joined: 28 Feb 2006
Posts: 3

PostPosted: Mon Jul 17, 2006 12:59 pm    Post subject: Re: client server programming Reply with quote

Josef Moellers ha scritto:

Quote:
pietro wrote:
hi all, I'm deploying a client/server application where the connection
is implemented by a socket.
I have a problem. When I close and restart client, the connection with
server application is lost and I cannot restore it. The only way I
found to restore it is to kill and restart both server and client.

Is it possible to re-establish my old connection with server via client
restart only?

If you write "I cannot restore it": what is the error you get?
How do you "close and restart client"? Is the socket correctly close()ed?

If the error message is something like "address already in use", you
might want to look at the SO_LINGER socket option.

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett


If my client module dies (via a sigkill or even a segmentation fault),
when I restart it, it simply doesn't work.
I don't obtain any error, so I have to kill also the server application
and then restart the server and the client properly.

So we are speaking about a scenario in which client exits in a non
regular way... (with no close(), return....).
Back to top
Josef Moellers
*nix forums Guru


Joined: 28 Feb 2005
Posts: 426

PostPosted: Mon Jul 17, 2006 1:20 pm    Post subject: Re: client server programming Reply with quote

pietro wrote:
Quote:
Josef Moellers ha scritto:


pietro wrote:

hi all, I'm deploying a client/server application where the connection
is implemented by a socket.
I have a problem. When I close and restart client, the connection with
server application is lost and I cannot restore it. The only way I
found to restore it is to kill and restart both server and client.

Is it possible to re-establish my old connection with server via client
restart only?

If you write "I cannot restore it": what is the error you get?
How do you "close and restart client"? Is the socket correctly close()ed?

If the error message is something like "address already in use", you
might want to look at the SO_LINGER socket option.


If my client module dies (via a sigkill or even a segmentation fault),
when I restart it, it simply doesn't work.
I don't obtain any error, so I have to kill also the server application
and then restart the server and the client properly.

If it is your code, you should be able to add appropriate diagnostics, e.g.

if (connect(sd, ...) == -1)
perror("connect");

as a simple example.

Also strace may be your friend if you don't really know where the error
occurs of if it's not your code.

"simply doesn't work" is not a very helpfull diagnostic!

Quote:
So we are speaking about a scenario in which client exits in a non
regular way... (with no close(), return....).

I thought so.

You can still set the SO_LINGER option when the socket is open/connected!
Rich Stevens' book "Unix network programming" has this to say about the
effect of SO_LINGER:
"If the linger time is specified as zero, any remaining data to be sent
is discarded when the socket is closed."

So, try to set SO_LINGER to 0.

Josef

Oh, btw IANANE (I am not a networking exper Wink
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
Back to top
Nils O. Selåsdsal
*nix forums addict


Joined: 05 Nov 2005
Posts: 85

PostPosted: Mon Jul 17, 2006 6:36 pm    Post subject: Re: client server programming Reply with quote

pietro wrote:
Quote:
hi all, I'm deploying a client/server application where the connection
is implemented by a socket.
I have a problem. When I close and restart client, the connection with
server application is lost and I cannot restore it. The only way I
found to restore it is to kill and restart both server and client.

Is it possible to re-establish my old connection with server via client
restart only?
Yes, program the server so it goes back to accepting a new connection

when the current one fails/disconnects.
Or make the server handle concurrent connections..
Back to top
David Schwartz
*nix forums Guru


Joined: 26 Feb 2005
Posts: 914

PostPosted: Tue Jul 18, 2006 4:56 am    Post subject: Re: client server programming Reply with quote

pietro wrote:

Quote:
If my client module dies (via a sigkill or even a segmentation fault),
when I restart it, it simply doesn't work.

You need to troubleshoot it and figure out why it doesn't work.

Quote:
I don't obtain any error, so I have to kill also the server application
and then restart the server and the client properly.

Sounds like it's the server that has the problem. It has crashed or
locked up. Troubleshoot it.

Quote:
So we are speaking about a scenario in which client exits in a non
regular way... (with no close(), return....).

Right, and the server probably doesn't have appropriate code to handle
this scenario. So fix it. Troubleshoot it if you're not sure exactly
what the problem is.

One trick might be to compile the server with debug information and
attach a 'gdb' process to it as soon as it stops responding. Then you
can see what code it's running.

One problem might be a 'read' loop that doesn't terminate if 'read'
returns zero. It's hard to say since you've told us nothing about your
code.

DS
Back to top
jasen
*nix forums beginner


Joined: 18 Jul 2006
Posts: 3

PostPosted: Tue Jul 18, 2006 10:08 am    Post subject: Re: client server programming Reply with quote

On 2006-07-17, pietro <tremendo1977@virgilio.it> wrote:
Quote:
hi all, I'm deploying a client/server application where the connection
is implemented by a socket.
I have a problem. When I close and restart client, the connection with
server application is lost and I cannot restore it.

The server needs to listen for further connections and use either select()
or multiple threads to handle them. either that or use inetd to start a new
instance of the server for each connection.

--

Bye.
Jasen
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 7:04 am | All times are GMT
navigation Forum index » *nix » Linux » development » apps
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Transfer qmail email account to postfix server tallman Postfix 0 Thu Jun 05, 2008 12:43 pm
No new posts Postfix SMTP client issues damber Postfix 1 Sat Apr 19, 2008 11:33 am
No new posts NFS server on Solaris 10 gurgle Solaris 0 Tue Sep 04, 2007 7:05 pm
No new posts Help required for configuring the VPN Server in Linux SHERDIL security 0 Sun Nov 19, 2006 2:22 pm
No new posts Need Help with Program in Perl on a Netware Server fhadzocos@gmail.com Perl 3 Fri Jul 21, 2006 1:57 pm

Bankruptcy Certification | Mobile Phone | Credit Card | Myspace Backgrounds | Free Photo Storage
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2317s ][ Queries: 16 (0.1382s) ][ GZIP on - Debug on ]