|
|
|
|
|
|
| Author |
Message |
pietro *nix forums beginner
Joined: 28 Feb 2006
Posts: 3
|
Posted: Mon Jul 17, 2006 8:46 am Post subject:
client server programming
|
|
|
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
|
Posted: Mon Jul 17, 2006 10:59 am Post subject:
Re: client server programming
|
|
|
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
|
Posted: Mon Jul 17, 2006 12:59 pm Post subject:
Re: client server programming
|
|
|
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
|
Posted: Mon Jul 17, 2006 1:20 pm Post subject:
Re: client server programming
|
|
|
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
--
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
|
Posted: Mon Jul 17, 2006 6:36 pm Post subject:
Re: client server programming
|
|
|
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
|
Posted: Tue Jul 18, 2006 4:56 am Post subject:
Re: client server programming
|
|
|
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
|
Posted: Tue Jul 18, 2006 10:08 am Post subject:
Re: client server programming
|
|
|
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 |
|
 |
|
|
The time now is Thu Jan 08, 2009 7:04 am | All times are GMT
|
|
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
|
|