Solved

Socket Programming Question

Posted on 2006-12-01
7
293 Views
Last Modified: 2010-04-01
Hi Experts,

I am working on a client application that talks to the server through socket and exchange messages.  Basically, it is a request response model.  Client send requests and get results from the server.  My client is a library that is loaded by another process.  So, that process(say P1) communicate with the Server process(P2) using client library.  

The library should indicate to P1 whenever the connection with P2 goes down.( For example, the server is reset).

How do I do this?  Should I have another thread that checks if the connection is up periodically?

Thanks,
0
Comment
Question by:ambuli
7 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 18058504
You will get an ECONNRESET return code (prefix that with WSA on Windows) when trying to perform any connection on a socket that has that problem, just react to that accordingly any you have covered the issue.
0
 
LVL 3

Assisted Solution

by:Akumas
Akumas earned 100 total points
ID: 18058540
depends on your platform.
in windows, when you try to recv data from remote server using Winsock api "recv",
if you recv zero length data, it indicates connection is closed graceful by remote server.
if you get a SOCKET_ERROR, it indicates connection is unvailable such as network problem, you should
 use WSAGetLastError to get result.

see msdn for details.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/recv_2.asp
0
 

Author Comment

by:ambuli
ID: 18058777
I am using Linux platform.  Would I get the ECONNRESET when I try to send data?  The connection should have been established and the server reset.  So, without knowing that the server has reset, the client would try to send data.  If sending sets this error that is good.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:ambuli
ID: 18058909
I tested using a simple client and server.  while I was running both of them I terminated the server.  The error is not ECONNRESET. As I am using a TCP wrapper class with no source code I am not sure what the exact error number was.  But, the wrapper class handle this error.   Why I didn't see the error.
0
 
LVL 11

Accepted Solution

by:
DeepuAbrahamK earned 300 total points
ID: 18060148
There could be multiple sccenarios:

1/  Server machine is switched off
2/  Server application not working

So I would recommend you to check "PING" technique to tackle the point 1, and the application based send data and receive data (which can act as heart beats).This can run in seperate threads.These are the normal pracatices.

Best Regards,
DeepuAbrahamK
0
 

Author Comment

by:ambuli
ID: 18061126
Hi there,
If I need to implement this, I would have a thread that sleeps for a while and then check if the connection is ok. What message should I send to check if the connection is up?  I am not familiar with the ping technique.  So, please provide me some more information.  Thanks
0
 

Author Comment

by:ambuli
ID: 18062242
Can somebody provide me a pseudo code or a sample for a heartbeat example.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

776 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