Solved

how check socket's close

Posted on 2001-07-01
7
297 Views
Last Modified: 2008-03-17
i have a c/s program in unix.but i don't check the close of client's.
  at first ,i check the return of recv,if it equal 0,then the client is close.and i do in my way.
  but if the client host is shutdown.the return of recv is -1.so i couldn't check the status of client's quit.
  how do i do ?
0
Comment
Question by:tsjit
7 Comments
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6243893
I recv return -1 that mean some error. If You don't want to check error (some socket get last error function) You can said that it mean Your socket is closed and no more available. That mean that problem is ion your side of communication.
0
 

Author Comment

by:tsjit
ID: 6243989
 i used socket nonblock.and every time i check the error no ,it is 11.after i shutdown the client's host.the error no is not change.
  qnx is the opration of me.
0
 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6244034
I use MSVC 6.0. You could check is this error for SOCKET_INVALIDHANDLE that mean that your socket is closed.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 10

Expert Comment

by:makerp
ID: 6244087
this is from my Stream class, it checks for close and error. it is for windoze but you will get the idea

int Stream::recvData(char *buffer,int len,int option)
{
     int so_far = 0;
     int res = 0;
     so_far = recv(sock,buffer,len,0);
     if(so_far == SOCKET_ERROR || so_far == 0)
     {
          last_error = WSAGetLastError();
          return FAILURE;    
     }
     /* should we wait for 'len' to arrive */
     if(option == RECV_UPTO_LEN)
     {
          while(so_far < len)
          {
               res = recv(sock,buffer + so_far,len - so_far,0);
               if(res == SOCKET_ERROR || so_far == 0)
               {
                    last_error = WSAGetLastError();
                    return FAILURE;
               }
               so_far += res;
          }
     }
     return so_far;
}

0
 

Author Comment

by:tsjit
ID: 6244219
thank you ,but i am in qnx opration.are you give me more detail about unix and so.because they can not supple WSAGetLastError() or some like this.
         
0
 
LVL 11

Expert Comment

by:griessh
ID: 6820141
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and PAQ at zero points since nobody had a solution for you.

The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner

0
 

Accepted Solution

by:
ComTech earned 0 total points
ID: 6837812
This question will be moved to PAQ.

Regards,
ComTech
CS @ EE
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 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 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.

746 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

13 Experts available now in Live!

Get 1:1 Help Now