Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Socket Programming Question

Posted on 2006-12-01
7
Medium Priority
?
323 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:
Deepu Abraham 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

604 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