?
Solved

Socket Programming Question

Posted on 2006-12-01
7
Medium Priority
?
313 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
[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
7 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 400 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 400 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
Technology Partners: 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!

 

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 1200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

800 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