Solved

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

Posted on 2008-06-24
5
2,996 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error C2678: binary '!=': no operator found... 4 65
c++ using a LPCOLESTR * and adding a string varaible to the Pointer 2 76
Bartender Integration Builder 3 74
Outlook 13 85
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

697 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