473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dealing with dead sockets on a winsock2 sever

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

Jul 23 '05 #1
8 2044

"Holger Fleckenstein" <ha**********@web.de> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
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
Jul 23 '05 #2
REH

"Holger Fleckenstein" <ha**********@web.de> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
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
Jul 23 '05 #3
Well, the thing is, that the client is written in IDL. I don't think
they implemented this option.

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

Jul 23 '05 #5

"Holger Fleckenstein" <ha**********@web.de> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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.
Jul 23 '05 #6
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

Jul 23 '05 #7
REH

"Holger Fleckenstein" <ha**********@web.de> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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
Jul 23 '05 #8
> 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.

Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Nick Keighley | last post by:
I'm probably missing something rather obvious, but is there a known problem with getting a Python based socket program to communicate with a C based socket program? A simple echo server written in...
1
by: Ben | last post by:
I've written a fair amount of sockets code using the Winsock2 API, but I am having some trouble converting to the .Net Sockets API, specifically asynchronous sockets. What I have is a form that is...
0
by: Holger Fleckenstein | last post by:
Hi I have written a C++ server and an IDL client, that are supposed to communicate over sockets. Circumstances require, that only one client can connect at a time, and possible others are...
3
by: John P | last post by:
Hi, I know that some older Unix programs that compile with GCC use socket.h to connect to and execute other programs. However, I am using Visual C++ 6.0 and it doesn't seem to have socket.h...
7
by: sareel | last post by:
I need the explanation/code to transmit a complex datastructure like Linked list or binary tree using sockets from client to sever...
8
by: JDavis | last post by:
I am using System.Net.Sockets to connect a client socket to a server that requires three inputs when I connect: host, port and an identification number that identifies the person connecting. ...
1
by: ishay44 | last post by:
I use Winsock2 (WS2_32.DLL) and i want to canceling the 'select()' blocking, in Windows Sockets 1.1 it was possible using the WSACancelBlockingCall(), but it removed for Winsock2 so how can cancel...
25
by: 4.4.bsd | last post by:
Is there any possible way to use sockets in C, so i can finish a instant messenger program?
4
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.