Solved

Socket Programming Question

Posted on 2006-12-01
7
272 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now