Solved

How can I detect the connected socket disconnected (broken down) instantly ?

Posted on 2008-06-24
5
2,997 Views
Last Modified: 2013-11-20
I have a TCP socket Server in Windows PC and have 10 TCP socket Clients (Linux) on 10 PC.
After the Server and the Clients start, the Clients will connect to the Server and
does keep the connections for data transfer.
The Server listen to and create a new work thread for the connected client socket......
I want to know the 10 connections are always on, so the 10 client sockets must periodly
send the bit data to the Server to make sure that it is connected.......
I need to find the more efficient method to do that ?  Maybe I can know each connection
is down off immediately ?
0
Comment
Question by:RandallLin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 3

Expert Comment

by:winstonep
ID: 21853739
The first thing that springs to mind is to ask what OS you are using for the server?

I haven't found anything free but have a look at http://www.download.com/KeepAlive-Pro/3000-2084_4-10297409.html which is Keep Alive Pro and has a 15 day free trial. It may help.
0
 
LVL 3

Expert Comment

by:winstonep
ID: 21853747
Ok that program may not be the right one sorry... :-( I will see what I can find as I know there is something out there that can do this.
0
 
LVL 4

Accepted Solution

by:
bdunz19 earned 50 total points
ID: 21864381
Hi,
When your server, which I'm guessing is the one running on Windows, is listening for connections what sort of socket model are you using? Are you using an asyncronous model like EventSelect or IO Comptetion Ports? If you are just using the syncronous model, then when your server calls recv() it will wait untill either data is recieved from the client or the connection is closed. If recv() returns SOCKET_ERROR, then chances are the client is disconnected. You can check this further by calling WSAGetLastError(). If you are using any of the async models then you would know that you can easily recieve close messages when the clients disconnect.

Also, when you have the clients sending data periodically that works as a sort of keep alive. I've noticed that if my client programs do not do this then the connections will close after a while of inactivity. So in other words, using a keep alive method is not a bad idea to have in a client program, but the server should always be aware immediatly when the client disconnects using the methods I described above.

Hope this helps,
Brandon
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 50 total points
ID: 21893284
>>>> so the 10 client sockets must periodly
>>>> send the bit data to the Server to make sure that it is connected.......
If the Server has a own thread for each connection, the thread should call select with timeout within the infinite loop. If the connection is broken, select would return SOCKET_ERROR (see th comment of bdunz19 above). If not, you can count the timeouts happened since the last receive and break the connection after having waited for too long.

Note, if not using native sockets but the Windows API, select is either WSAEventSelect or WSAAsyncSelect.

Regards, Alex
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question