Dealing with dead sockets on a winsock2 sever

  • Thread starter Holger Fleckenstein
  • Start date
H

Holger Fleckenstein

Hi, I have a problem with a server socket (winsock2.h).

I do all standard stuff like listen(), accept() and so on, which all
works fine. I only want one client to be able to connect at a time and
none to be backlogged during this time. So I stop listening, as soon as
one client connects and restart doing it after the client is done.
While a client is connected the server most of the time waits [recv()]
for commands and then deals with them.

Now the actual problem is, that the clients die sometimes (for reasons
which are out of my range) and the server does not always realize this.
It just keeps sitting there waiting for commands, that never come
anymore. And for the reasons mentioned above, no other clients can
newly connect. The only thing I can do in such a situation is to kill
and restart the server.

Is there a standard way for the server to realize, when a client
connected on a socket is dead, so I can make it go back into listen
mode?

Thanks, Holger
 
J

Jon Slaughter

Holger Fleckenstein said:
Hi, I have a problem with a server socket (winsock2.h).

I do all standard stuff like listen(), accept() and so on, which all
works fine. I only want one client to be able to connect at a time and
none to be backlogged during this time. So I stop listening, as soon as
one client connects and restart doing it after the client is done.
While a client is connected the server most of the time waits [recv()]
for commands and then deals with them.

Now the actual problem is, that the clients die sometimes (for reasons
which are out of my range) and the server does not always realize this.
It just keeps sitting there waiting for commands, that never come
anymore. And for the reasons mentioned above, no other clients can
newly connect. The only thing I can do in such a situation is to kill
and restart the server.

Is there a standard way for the server to realize, when a client
connected on a socket is dead, so I can make it go back into listen
mode?

Thanks, Holger

Why can't you poll the client every few min or seconds or whatever you wish
and see if it responds?

How else can you know its dead? Its not like it will dead you its fixing to
die..

Jon
 
R

REH

Holger Fleckenstein said:
Hi, I have a problem with a server socket (winsock2.h).

I do all standard stuff like listen(), accept() and so on, which all
works fine. I only want one client to be able to connect at a time and
none to be backlogged during this time. So I stop listening, as soon as
one client connects and restart doing it after the client is done.
While a client is connected the server most of the time waits [recv()]
for commands and then deals with them.

Now the actual problem is, that the clients die sometimes (for reasons
which are out of my range) and the server does not always realize this.
It just keeps sitting there waiting for commands, that never come
anymore. And for the reasons mentioned above, no other clients can
newly connect. The only thing I can do in such a situation is to kill
and restart the server.

Is there a standard way for the server to realize, when a client
connected on a socket is dead, so I can make it go back into listen
mode?

Thanks, Holger

OT, but do a google search for the socket option KEEP_ALIVE.

REH
 
H

Holger Fleckenstein

Well, the thing is, that the client is written in IDL. I don't think
they implemented this option.
 
H

Holger Fleckenstein

The client is not really designed to respond to requests from the
server. It's more or less a one-way street.
 
J

Jon Slaughter

Holger Fleckenstein said:
The client is not really designed to respond to requests from the
server. It's more or less a one-way street.

ok... simple

have the client "poll" the server.

The server should expect something from the client every x seconds... if it
doens't recieve something then it disconnects.
 
S

sandSpiderX

Hi,

Its important to understand are the clients syncronous (sending
messages regularly evry few time) or asynchronous (sending messages at
irregular intervals)

If they are synchronous , then just make server to listen for some
predestined time and then accept the client conenction as dead..

If they are asynchronous , then the best way is to generate
reconnecttion requests to the client, if the client accepts the
reconnection request , its cool....if not treat them as dead...

Hope this solves your problem....

sandSpiderX
 
R

REH

Holger Fleckenstein said:
Well, the thing is, that the client is written in IDL. I don't think
they implemented this option.

IDL? You mean CORBA? Go here: comp.object.corba

REH
 
H

Holger Fleckenstein

IDL? You mean CORBA? Go here: comp.object.corba

No, I mean Interaktive Data Language.
Anyhow, I found a solution:
If you configure the server socket to be non-blocking, recv() will
return SOCKET_ERROR and create an error of WSAEWOULDBLOCK, if the
client has nothing to say. If the client is dead, it will return 0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top