Solved

Socket Programming Question

Posted on 2006-12-01
7
298 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dynamically allocate memory 9 63
Unresolved External Symbols 3 107
Issues with C++ Class 19 101
How to properly read C++ console input into several variables with scanf 2 20
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

829 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